glib does not call malloc()
every time it needs a new node in a data structure. If
it did, building linked lists (for example) would be
substantially slower. Instead, glib caches pools of
equal-sized "memory chunks" for use in these data
structures. Since the chunks are still available for
recycling when your program exits, they are never free()d. (Of course, the
operating system will reclaim the memory, but tools
such as ccmalloc and Purify will report it as a
memory leak.)
To get around this, you can plug a new GAllocator into most of the data
structures. A
GAllocator is a pool of memory as described
above. Just create an allocator manually, so you have a
pointer to it; you can then free the allocator when you
are finished.
Figure 1 summarizes the relevant functions for
GList. A quick glance
through glib.h will reveal
the corresponding functions for other data structures.
The name argument to g_allocator_new() is used in
debugging messages; the
n_preallocs argument is passed through to g_mem_chunk_new().