Re: Will this create a memory leak? Can't determine from top.



On Tue, 2005-06-28 at 10:43 -0400, Tristan Van Berkom wrote:
Tristan Van Berkom wrote:
Bartek Kostrzewa wrote:

Should I define an array of char pointers
*message[TABLE_SIZE][TABLE_SIZE] to hold the pointers created by
g_strdup_printf or would that just be a waste of memory?


   I guess you want to free the string when the object emmiting the
signal is finalized, in that case you can use a function like
g_object_weak_ref like so:

Come to think of it, you can make it even simpler by just doing:

   g_object_weak_ref (G_OBJECT (button[i][j]),
                      (GWeakNotify)g_free, string);

Cheers,
                         -Tristan

Oh indeed, I rembember that from the second chapter (Gnome2 Devs guide),
it was a sidenote somewhere :) shouldn't have read it while being so
darn tired. On the other hand though, here's what Warkus (or rather the
translator) writes about something as important as this:

Don't confuse g_object_*_weak_pointer() with g_object_weak_*ref(). The
latter function enables you to call a notification function when GObject
is destroyed, BUT WILL NOT BE COVERED IN THIS BOOK. [emphasis mine]

It's a shame that Mathias was forced to keep the page-count down. The
guide could have been much better with some more gory details about the
MANY MANY useful things in the libs.

Thanks, I'll keep your solution in mind when I assign a large number of
elements to an object.

-Bartek




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