Given the following code:
#include
int main()
{
int *p;
p = (int *)malloc(10 * sizeof(int));
while(1);
return 0;
}
<
the memory is actually not "free()"d at all.
memory acquired by the operating system is page size (4kbytes of memory usually). whenever a process runs out of memory it acquires additional pages, these are the space malloc() actually uses. when a process terminates all pages are returned to the operating system making calling free actually unnecessary. if your programme is a server or similar every piece of memory that is never freed will only be returned when the programme is actually killed - making it every more memory hungry.