Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 02-29-2004, 04:45 PM   #1
LQ Newbie
Registered: Feb 2004
Posts: 1

Rep: Reputation: 0
Question what happens to un"free"d memory?

Hey group,

I have this very basic question:

What happens when a process malloc()'s a chunk of heap memory and forgets to free() the memory? Does the alloc 'ed memory becomes UNRECOVERABLE by the Operating System for ever, till a reboot?

Or when a process exits, either by calling exit() or gets a signal that exits the process, does the whole memory allocated for this process by the operating systems is recovered for use by other process? In this case I will not see the available memory decrease for ever as long the "bad" process either crashes or exits because the garbage memory will be recovered by the operating system.

It would be great if some one could answer me a little details on this matter or you please point me to some articles on this subject?

Thanks a lot people.
Old 02-29-2004, 05:02 PM   #2
Registered: Feb 2004
Posts: 40

Rep: Reputation: 15
I believe that as soon as the process that allocated the memory finishes, all the memory that it allocated is returned to the system - unless it spawns new processes that are still running....

However the danger with memory leaks is that your process may continually consume more and more memory - this is especially relevant for process that need to be running constantly.

In addition, if you do not free memory, then your program may have intermittent errors that are very hard to track down.

For example you go over the bounds of an array by accident. Sometimes when you run the program, the neighbouring memory belongs to your program - it was malloc'ed but not freed yet. In this case it will not generate an error. You may run it another time, and the neighbouring memory does not belong to you, and you will generate a segmentation fault.

By the way, if you use C++, you do not need to use malloc, use new instead.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Differences between the "free" and "paid" versions eraser Linux - General 4 11-18-2015 07:30 PM
Telling people to use "Google," to "RTFM," or "Use the search feature" Ausar General 77 03-21-2010 12:26 PM
"Xlib: extension "XFree86-DRI" missing on display ":0.0"." zaps Linux - Games 9 05-14-2007 04:07 PM
Can you explain the difference between "Free Software (GNU)" and "Open Source"? vharishankar General 5 03-03-2005 10:40 AM
"Undeleting" data using grep, but get "grep: memory exhausted" error SammyK Linux - Software 2 03-13-2004 04:11 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:45 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration