Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Will the allocated memory be released after process exits?

Reply
Thread Tools

Will the allocated memory be released after process exits?

 
 
lovecreatesbeauty
Guest
Posts: n/a
 
      10-24-2005
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?



Sincerely,

lovecreatesbeauty

 
Reply With Quote
 
 
 
 
Peter Nilsson
Guest
Posts: n/a
 
      10-24-2005
lovecreatesbeauty wrote:
>
> 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? )?


The standard does not specify this.*

> Or will the allocated memory be released after program exits?


On modern desktop operating systems, yes. On more specialised
operating systems, perhaps not.

You should structure your code so that you can easily deallocate
any and all dynamic objects. However, many programs avoid actually
doing the deallocation on program exit because, one some systems,
it can needlessly cause the system to thrash.

However, the more complicated your program, the more sense it makes
to deallocate memory. If system resources are tied to given memory
allocations, then the deallocation routines in your code can (and
should) untie/close those system links as the same time.

So, the choice is yours.

* Certainly not in any way that a strictly conforming program could
ever tell.

--
Peter

 
Reply With Quote
 
 
 
 
Pacher R. Dragos
Guest
Posts: n/a
 
      10-24-2005

lovecreatesbeauty wrote:
> 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?


If you include your code in a try/catch block it will be dealocated by
garbage collector. But this is implemented only in a few compilers as
a add-on, like lcc.
Please ermember that this has nothing to do with the C standard.
example
try
{
//code here
}

catch(/*Exception e*/)
{
//do something with the exception or throw it again
}

If you know java this will be very easy.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
will the memory allocated by malloc get released when program exits? keredil@gmail.com C Programming 30 07-03-2011 05:09 AM
[C/Linux] How to get amount of allocated memory from within a process (heap size) Gennady Bystritsky Ruby 4 07-27-2009 06:56 PM
How to check memory size allocated to JVM? Laura Heinzmann Java 1 02-16-2005 04:37 AM
Dynamically Allocated Memory vs. Statically allocated Memory csnerd@gmail.com C++ 5 12-09-2004 01:44 AM
Duplicate memory allocated by IndexedTriangleArray Duncan Java 0 07-21-2003 07:25 PM



Advertisments