Seems like even after I free all the memory for a Linux process that was allocated by malloc()
,
memory is still reserved for the process and not returned to the OS.
Running valgrind massif
tool by default reveals no leakages.
Running valgrind
with --pages-as-heap=yes
reveals this:
->13.77% (7,655,424B) 0x35FEEEB069: brk (brk.c:31)
->13.77% (7,655,424B) 0x35FEEEB113: sbrk (sbrk.c:53)
->13.77% (7,655,424B) 0x35FEE82717: __default_morecore (morecore.c:48)
->13.77% (7,655,424B) 0x35FEE7DCCB: _int_malloc (malloc.c:2455)
->13.77% (7,655,424B) 0x35FEE7F4F1: malloc (malloc.c:2862)
so even though memory was already freed by free()
, it seems that malloc
called brk/sbrk
and did not return this to the OS.
how can I force free()
to call sbrk()
immediately and return all memory back to the OS ?
I am running on a very low end platform which every MB counts.
Thanks in advance.
malloc
/free
calls, it's the operating system that keeps the previously allocated memory-pages mapped to your process. If the OS needs those free pages it will take them when needed. I'm to lazy to find a duplicate, but there are many duplicates of this question. – Wiburgfree()
. – Sequential