[vox-tech] not freeing heap memory

Tim Riley vox-tech@lists.lugod.org
Tue, 29 Apr 2003 10:27:14 -0700


Peter Jay Salzman wrote:

> when you don't free memory allocated allocated from the heap on a linux
> system, the memory is recovered after the application ends.

Yes. Try this with "top" running in another window, and watch the
used memory decline and then jump back. "Garbage collection"
is like playing with your toys and then leaving your room and
returning with everything put away.

#include <stdio.h>
#define MEMORY_BLOCK 1048576

int main()
{
        int i;
        long total = 0;

        for( i = 0; malloc( MEMORY_BLOCK ); i++ )
        {
                printf( "total = %ld\n", total += MEMORY_BLOCK );
                if ( !(i % 100 ) ) sleep( 1 );
        }
        exit( 0 );
}

>
>
> are there any operating systems where the memory is only recovered after
> a reboot?
>

Definitely Windows 3.1 and before, but I'm still seeing advertisements
for memory leak utilities in computer magazines.

>
> pete
>
> --
> GPG Instructions: http://www.dirac.org/linux/gpg
> GPG Fingerprint: B9F1 6CF3 47C4 7CD8 D33E 70A9 A3B9 1945 67EA 951D
> _______________________________________________
> vox-tech mailing list
> vox-tech@lists.lugod.org
> http://lists.lugod.org/mailman/listinfo/vox-tech