Search code examples
arrayscmallocheap-memorycalloc

How long does Linux take to clear the heap memory


I was wondering... suppose I've dynamically allocated an array like

array = calloc(n, sizeof(float));

or something similar. And also if n is a really large number, (~ 1 million, for arguments sake), how long would Linux take to clear the heap memory if I didn't free() it at the end? I know any OS would go around and clear un-freed and unused heap memory areas. But I assume how long it takes to do that is OS dependent.


Solution

  • If a process is terminated (either voluntarily or by force), all its heap memory will be reclaimed immediately by an operating system including Windows, Linux and OS X.