C/C++ Programming : Do you know that free or delete will NOT release memory back to OS ?

Note:  Based on observations and tests  made on Solaris OS 10 with Solaris compilers.

When you call free() or delete(), it will NOT really release any memory back to OS. Instead, that memory is kept with the same process until it is terminated. However, this memory can be reused for any future allocations by the same process.

This ‘freed’ memory is never released to OS, even when the system is out of memory and other processes need memory. That means, a process is stuck with the largest level of memory allocation throughout its life time.

This is big concern for most processes that are expected to run (literally) forever without a restart.

There is an alternative, by linking to mapmalloc library, that uses map/unmap instead of sbrk for memory allocation. When linked with this library, memory could be really released to operating system when free/delete is called. However, memory allocation could be potentially 5 times slower. One heck of a trade off!

Hope this information will help in your designs.


[...] keep tabs on what’s going on with C++ around the web, I chanced upon this short and succinct article about ‘free’ and ‘delete’ not returning memory to the OS from Thought Garage which starts with: When you call free() or delete(), it will NOT really [...]

Popular posts from this blog

USCIS Selects Final H1B Petitions by Random Selection - Almost a 50% chance for each Application

H1B 2008:USCIS released Preliminary Numbers

Just Make It Happen. Its 2010.