In a C code I have forked a child and then i give an exit(1) at the end of the child process. But does exit(1) release the memory used by the child process for its execution?
If not how do i make the child process free the memory it is using after it cimpletes its execution?
Page 1 of 1
release memory used by a child process
#2
Posted 19 March 2009 - 03:05 AM
Hey There,
Generally, the exit will almost always take care of cleaning up the memory. If you want to be 100% sure, you should call free() for any memory allocated, even to child processes (forks, execs).
A lot of people don't believe it's necessary at all, and they do have a point in that it almost-never needs to be. Specifically freeing the memory won't hurt if the memory's already been freed, but it will give you the piece of mind that your child procs aren't the problem if you experience any general memory-leakage in your program. One less suspect
Best wishes,
Mike
Generally, the exit will almost always take care of cleaning up the memory. If you want to be 100% sure, you should call free() for any memory allocated, even to child processes (forks, execs).
A lot of people don't believe it's necessary at all, and they do have a point in that it almost-never needs to be. Specifically freeing the memory won't hurt if the memory's already been freed, but it will give you the piece of mind that your child procs aren't the problem if you experience any general memory-leakage in your program. One less suspect
Best wishes,
Mike
The greatest viral marketing idea of all time, get your copy of this Free Report now!
----
Linux Tips, Trick and Advice -- The Linux and Unix Menagerie
----
Linux Tips, Trick and Advice -- The Linux and Unix Menagerie
#3
Posted 19 March 2009 - 09:55 AM
Thanks Mike.
Wont free() free a memory that is allocated using malloc(),calloc() or realloc().
In my case,even if i exit the child giving exit(1) at the end of the child. But i suppose the memory the child process was using for its execution was not freed as tha amount of memory that was used to run the entire program(i.e parent + all its child) has exceeded the quota allocated to it.
Wont free() free a memory that is allocated using malloc(),calloc() or realloc().
In my case,even if i exit the child giving exit(1) at the end of the child. But i suppose the memory the child process was using for its execution was not freed as tha amount of memory that was used to run the entire program(i.e parent + all its child) has exceeded the quota allocated to it.
#4
Posted 14 April 2009 - 09:18 PM
There is something you can do in wither Java2 or C/C++
that being call destroy or delete on your variables after anything that can be freed.
that being call destroy or delete on your variables after anything that can be freed.
Share this topic:
Page 1 of 1

Help












