Why do processes never decrease in size?

Why do processes never decrease in size?


When you free memory back to the heap with free(), on almost all
systems that doesn't reduce the memory usage of your program.
The memory free()d is still part of the process' address space,
and will be used to satisfy future malloc() requests.



If you really need to free memory back to the system, look at using
mmap() to allocate private anonymous mappings. When these are
unmapped, the memory really is released back to the system. Certain
implementations of malloc() (e.g. in the GNU C Library)
automatically use mmap() where available to perform large
allocations; these blocks are then returned to the system on
free().



Of course, if your program increases in size when you think it
shouldn't, you may have a `memory leak' -- a bug in your program that
results in unused memory not being freed.






Home FAQ