Review your favorite Linux distribution.
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 07-20-2009, 02:25 AM   #1
LQ Newbie
Registered: Jul 2009
Posts: 1

Rep: Reputation: 0
system doesnt reclaim the freed memory after free()

In our application we do huge amounts of allocations (malloc) and deallocatoins (free) in bursts. But when the per process vm size or % MEM is checked the memory used doesn't come down after the free is done.

It comes down only after some other new allocations/deallocations happen.
Have tried with EF builds as well but was of no use.

Any pointers would be greatly appreciated.
Old 07-20-2009, 09:39 PM   #2
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
There's not necessarily a 1::1 relationship between memory you "malloc()" (a C runtime library function) and memory allocated to your process (at the kernel level).

The same is true of any modern OS, btw. You would encounter pretty much the same thing if you happened to be running your app on Windows, on Mac OS X or on Solaris.
Old 07-20-2009, 10:56 PM   #3
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 8,444
Blog Entries: 4

Rep: Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896
When an application allocates and frees memory, it's actually using application-level code which (as necessary) turns to the operating system to obtain chunks of memory to add to its pool of available storage. The application-level code then suballocates the large chunks of storage it has thus obtained.

Usually, these chunks are not "given back" to the operating system until the application ends, or when a chunk is found to be completely free (and perhaps, has been so for some time). It takes a lot of time to go to the operating system to get more storage.

Also remember that all of the storage obtained by an application is virtual, which means that storage really isn't being "wasted." Application storage management routines are designed to be favorable to virtual storage implementations.

The application behavior you are seeing is by-design.


leak, memory, pool, system

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
Why doesnt top or free show swap memory usage ? exceed1 Linux - General 15 08-03-2009 08:38 PM
Memory not being freed after program is finished running. keiths121 Linux - Newbie 5 06-03-2009 11:41 AM
pthreads virtual memory usage -- memory is not freed after thread exit minimol Linux - General 2 05-26-2009 01:19 AM
How does the cdev_alloc memory get freed up? nabramovitz Linux - Kernel 2 03-28-2008 07:04 PM
Freeing unused kernel memory: 228k freed bodedeb Linux - General 8 10-28-2003 03:59 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:24 AM.

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