Unix/Linux Forum: release memory used by a child process - Unix/Linux Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

release memory used by a child process Rate Topic: -----

#1 User is offline   sunaina Icon

  • Newbie (User Level: 0/10)
  • Group: Members
  • Posts: 4
  • Joined: 16-March 09

Post icon  Posted 18 March 2009 - 08:30 AM

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?
0

#2 User is offline   eggi Icon

  • User Level: 6/10
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 311
  • Joined: 25-November 07
  • Location:Grayslake, IL USA

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
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
0

#3 User is offline   sunaina Icon

  • Newbie (User Level: 0/10)
  • Group: Members
  • Posts: 4
  • Joined: 16-March 09

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.
0

#4 User is offline   nicephotog Icon

  • Newbie (User Level: 0/10)
  • Group: Members
  • Posts: 8
  • Joined: 23-November 08
  • Location:Australia

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.
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Cambridge Plus :: Cambridgeshire Steam Rally :: Touch Sensor Chip :: Matchless Piston Rings
Unix Man Pages / Linux Man Pages :: HiFi Forum :: A14 Comments :: UNIX/Linux Forum Archives