473,888 Members | 1,559 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Regarding released memory.

Hi All,

I am learning C++ and have one question.

Using free or delete we can release the memory. After releasing memory
where this
released memory will go.. Does it go to back operating system?
Please explain.

Thanks in advance.
Vijay

May 31 '06 #1
13 1865
Vijay wrote:
Hi All,

I am learning C++ and have one question.

Using free or delete we can release the memory. After releasing memory
where this
released memory will go.. Does it go to back operating system?
Please explain.


That's specific to the implementation. It might go back or it might not.
Sometimes, it is only returned in blocks, so it will only go back when a
whole block has been freed.

May 31 '06 #2
Vijay wrote:
Hi All,

I am learning C++ and have one question.

Using free or delete we can release the memory. After releasing memory
where this
released memory will go.. Does it go to back operating system?


The standard does not make any promisses about the effects of delete other
than that it calls a deallocation function to deallocate the memory. What
happens is not further specified. This leaves considerable freedom to the
implementation.

As for free(), it is defined in the C standard. All that is guaranteed is
that the memory becomes available for further allocation. However, even
that is not to be taken seriously: implementations often take the license
to return the memory to the operating system, in which case the memory may
be acquired by other processes so that it is not available anymore.
Some implementations use mixed strategies, e.g., they keep a pool of memory
around from which allocations of small objects are served whereas big
objects are served via system calls to the underlying OS.

For good code, do not rely on assumptions about what new/delete or
malloc/free will actually do. Treat them as abstract programming primitives
for memory management.
Best

Kai-Uwe Bux

ps.: If you are learning C++, I would recommend that you focus on the use of
std::string and standard containers and iterators first. This will, for
good measure, reduce your needs to manage memory manually. Come back to
memory management once you learned about writing exception safe code. Many
traps and difficulties with memory management are seriously aggravated by
exceptions -- since every new must match with one and only one delete along
every possible path of flow control, the diversions of flow control induced
by exceptions make life harder. Explicit memory management in C++ is
difficult and you should not needlessly start out with one of the hardest
aspects of C++ programming: you are make the learning curve unnecessarily
steep.

May 31 '06 #3
Kai-Uwe Bux wrote:
Vijay wrote:
Hi All,

I am learning C++ and have one question.

Using free or delete we can release the memory. After releasing memory
where this
released memory will go.. Does it go to back operating system?


The standard does not make any promisses about the effects of delete other
than that it calls a deallocation function to deallocate the memory. What
happens is not further specified. This leaves considerable freedom to the
implementation.

As for free(), it is defined in the C standard. All that is guaranteed is
that the memory becomes available for further allocation. However, even
that is not to be taken seriously: implementations often take the license
to return the memory to the operating system, in which case the memory may
be acquired by other processes so that it is not available anymore.
Some implementations use mixed strategies, e.g., they keep a pool of memory
around from which allocations of small objects are served whereas big
objects are served via system calls to the underlying OS.

For good code, do not rely on assumptions about what new/delete or
malloc/free will actually do. Treat them as abstract programming primitives
for memory management.
Best

Kai-Uwe Bux

ps.: If you are learning C++, I would recommend that you focus on the use of
std::string and standard containers and iterators first. This will, for
good measure, reduce your needs to manage memory manually. Come back to
memory management once you learned about writing exception safe code. Many
traps and difficulties with memory management are seriously aggravated by
exceptions -- since every new must match with one and only one delete along
every possible path of flow control, the diversions of flow control induced
by exceptions make life harder. Explicit memory management in C++ is
difficult and you should not needlessly start out with one of the hardest
aspects of C++ programming: you are make the learning curve unnecessarily
steep.


Thanks for so valuable information.

One other doubt.

I have read in one e-book that new is allocating memory from 'free
storage' and malloc is allocating from heap.

Is it right?
If yes, then what is difference between free storage and heap?
Regards,
Vijay

May 31 '06 #4
Vijay wrote:
[snip]
One other doubt.

I have read in one e-book that new is allocating memory from 'free
storage' and malloc is allocating from heap.

Is it right?


No -- or, well, it is a rather meaningless statement: the C++ language does
not have a memory model distinguishing "free storage", "heap", or "stack".
As far as the programmer is concerned, memory is handled behind the scenes
by compiler magic. All we know about memory is
* that it consists of units that a capable of storing an unsigned char,
* that we can take the address of any object (because an object *is* a
region in memory although it might not need to be contiguous),
* that we can explicitly acquire and release memory by new and delete,
and probably a few more minor things that just escape me right now.

How the resource memory is handled by the implementation (e.g., whether it
comes segmented with a distinguished stack segment) is not specified by the
C++ standard.
Best

Kai-Uwe Bux

May 31 '06 #5

Vijay wrote:
Hi All,

I am learning C++ and have one question.

Using free or delete we can release the memory. After releasing memory
where this
released memory will go.. Does it go to back operating system?
Please explain.


No, I'm fairly sure that the released memory doesn't go anywhere but
instead stays put inside the computer.

Greg

May 31 '06 #6
Greg wrote:

Vijay wrote:
Hi All,

I am learning C++ and have one question.

Using free or delete we can release the memory. After releasing memory
where this
released memory will go.. Does it go to back operating system?
Please explain.


No, I'm fairly sure that the released memory doesn't go anywhere but
instead stays put inside the computer.


Where is that computer's operating sytem running, if not inside it?

May 31 '06 #7
On 31 May 2006 04:07:47 -0700, "Vijay" <mt******@gmail .com> wrote:
Hi All,

I am learning C++ and have one question.

Using free or delete we can release the memory. After releasing memory
where this
released memory will go.. Does it go to back operating system?
If there was a home for lost memories, then realeased memory returns
home after retiring.

But, what about virtual memory? It softly and suddnely vanishes away.

For the Snark was a boojum, you see
Please explain.


"Please explain" Is it not the typical ending of homework assignment?
Please explain.
Bets regards
May 31 '06 #8

Zara wrote:
On 31 May 2006 04:07:47 -0700, "Vijay" <mt******@gmail .com> wrote:
Hi All,

I am learning C++ and have one question.

Using free or delete we can release the memory. After releasing memory
where this
released memory will go.. Does it go to back operating system?


If there was a home for lost memories, then realeased memory returns
home after retiring.

But, what about virtual memory? It softly and suddnely vanishes away.

For the Snark was a boojum, you see
Please explain.


"Please explain" Is it not the typical ending of homework assignment?
Please explain.
Bets regards

haha.. Good question by Zara
Would like to inform Zara that have completed my class room study 2
year back.
Regards,
Vijay

May 31 '06 #9
Kai-Uwe Bux wrote:
Vijay wrote:

Hi All,

I am learning C++ and have one question.

Using free or delete we can release the memory. After releasing memory
where this
released memory will go.. Does it go to back operating system?

The standard does not make any promisses about the effects of delete other
than that it calls a deallocation function to deallocate the memory. What
happens is not further specified. This leaves considerable freedom to the
implementation.


By implementation, do you generally mean "compilier" ?

Joe
May 31 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
2520
by: Thomas Heller | last post by:
ctypes 0.9.2 released - Oct 28, 2004 ==================================== Overview ctypes is a ffi (Foreign Function Interface) package for Python 2.3 and higher. ctypes allows to call functions exposed from dlls/shared libraries and has extensive facilities to create, access and manipulate
2
3095
by: Sean | last post by:
Here is a confusion about free() and delete. Someone told me that the memory chunk allocated in c++ will be automatically released back to system for future use. I haven't been convinced. In C, main() { int* p p = malloc(100*sizeof(int)); return 0; //A
8
5283
by: Mike | last post by:
Hello, I have a few rather urgent questions that I hope someone can help with (I need to figure this out prior to a meeting tomorrow.) First, a bit of background: The company I work for is developing a web-based application, one part of which involves allowing the user the ability to page through transaction "history" information. The _summary_ history table will have the following fields: ServiceName, Date, User-Ref1, User-Ref2,...
29
4419
by: keredil | last post by:
Hi, Will the memory allocated by malloc get released when program exits? I guess it will since when the program exits, the OS will free all the memory (global, stack, heap) used by this process. Is it correct?
2
2084
by: lovecreatesbeauty | last post by:
Hello experts, When I allocate memory use malloc() and forget to call a corresponding free(), does this allocated memory lose forever after program exits (Can i regard it same as process exits? )? Or will the allocated memory be released after program exits?
18
5916
by: techie | last post by:
I have a VC++ client that creates a COM object that is implemented in C#. The problem is the COM object doesn't get released, so I get a memory leak. I have no problems creating the COM object and getting a pointer to the required interface (IATImportFilter) in the client: COleDispatchDriver* resultInterface = new COleDispatchDriver; if ( resultInterface == NULL ) return FALSE; COleException oOleException; BOOL success =...
1
2804
by: trialproduct2004 | last post by:
Hi all, I am having slight confusion regarding memory management in .net. Say suppose i have two application one is in C# and other is in MFC(VC++). Both of this application are using lots of memory. Suppose i run first C# application which has occupied all memory and
8
1697
by: someone | last post by:
Hey All: I have two pointers A & B pointing towards data objects C & D resp. Now I want to achieve the following: 1. Free up memory that A points to 2. Have A point towards D 3. Have B point to nothing. How could this be implemented efficiently?
0
9961
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11182
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10778
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9597
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7990
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5824
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4642
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4245
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3252
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.