Tuesday, April 15, 2008

Why free() is not reducing your memory footprint ?

It found very interesting to me, even after i free() d the some dynamically allocated memory with my program, the process seems not reducing any memory in my memory footprint.
And when i researched about this, came to know that, in almost all systems the freed memory will not go to the system heap. instead of it will be there in the process address space for the future memory allocations.
but there is a work around also, there is a function called mmap(), which is used for the private anonymous mappings.
when these are unmapped the memory really is released back to the system. some implementations of malloc()automatically use mmap() where available to perform large allocations; these blocks are then returned to the system on free()