Re: [gtk-list] GAllocator vs. g_free (was: GMemChunk for skip lists)



On Thu, 09 Mar 2000 13:07:18 PST, Derek Simkowiak said:
> 	I have recently learned that free() (or g_free() ) does not return
> the freed memory to the operating system until after the program is
> killed.  So if I g_malloc() a ton of memory, and then g_free() it, my
> program is still using a crapload of RAM until it is killed.

This depends on whether your malloc package is smart enough to call sbrk()
to release totally unused pages, and whether your operating system
understands how to do it.

QUick summary:  sbrk() is the system call to get/free heap memory pages
from the operating system.  malloc() then keeps track of what's allocated
in that heap.

IN any case, free() is usually pretty cheap, and a good idea.  Consider the
effect on swap space of these two code segments:

    for(i=0;i<100000;i++) {int *foo= malloc(1000); free(foo) };

    for(i=0;i<100000;i++) {int *foo = malloc(1000); }

Think about that. It's called "a memory leak". ;)

-- 
				Valdis Kletnieks
				Operating Systems Analyst
				Virginia Tech



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]