Re: Glib hashtable memory leak

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

 



Hrvoje Nikšić wrote:> On Wed, 2008-04-30 at 15:33 +0300, Ovidiu Gheorghies wrote:>> The following program appears to leak memory according to mtrace:> > For something to be considered a memory leak, the program must> accumulate the lost memory with each iteration of the suspected code> segment.  Memory tracers often do not have sufficient information to> distinguish genuine leaks from advanced allocation strategies, in which> the library keeps extra storage around for later reuse.  In your case,> you can convert your program to an infinite loop:> > #include <glib.h>> int main()> {>   GHashTable* hash_table;>   for (;;) {>     hash_table=g_hash_table_new(g_str_hash, g_str_equal);>     g_hash_table_unref (hash_table);>   }>   return 0;> }> > If there were a leak in g_hash_table_new/unref, this program would soon> consume large amounts of memory.  I observe that its memory stays within> bounds, which means that it doesn't leak, despite the mtrace diagnostic.
Good tip. I always do this to quickly identify if my programs have a leak,and then use valgrind et. al. to find where it is.
Make sure you `ulimit -v` appropriately though, as linux at leastbecomes unresponsive if you do have a leak and start swapping.
Pádraig.
_______________________________________________gtk-list mailing listgtk-list@xxxxxxxxxxxxx://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux