Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

free() not freeing memory in embedded linux.

I have allocated memory using malloc() in embedded Linux (around 10 MB). And checked the free memory it was 67080 kB but even after freeing it using free() it remains the same. It is only after the application is terminated the memory is available again. Does free() not make the freed memory available to the system, if so how to make it available.

like image 391
Chu Avatar asked Dec 06 '22 03:12

Chu


1 Answers

free is a libc library call. it marks heap space as available for reuse. It does not guarantee that the associated virtual mapping will be released. Only after a dirty virtual mapping is released by your OS, then that memory will be system wide free again. This can only happen in chunks of pages.

Also if you allocated memory using malloc and family and didn't use it then it didn't actually consume physical memory until then - so freeing it will do nothing.

like image 63
Sergey L. Avatar answered Dec 08 '22 16:12

Sergey L.