Re: does g_object_set_data() leak ?




On Mon, 2007-12-31 at 18:49 +0800, Gregory Hosler wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I'm having a suspicion that g_object_set_data() leaks. When you use
g_object_set_data(), it will store the key/data pair in a gHashTable in the
object's->data area. When the object is destroyed/freed/unref'ed, it seems to
appear that the memory used by the g_object_set_data() associations is not freed
along with the object.

yes, obviously: the GObject does not know how to free the data for you.

what you want is g_object_set_data_full(), where you can pass a
GDestroyNotify function which will be called when the data is destroyed.

In general, I'm using g_object_set_data() to store pointers to various and
asundry widgets. 

don't, unless the amount of data you're actually binding is small and
you know exactly how to manage its lifetime. what you should be doing is
creating a new GObject class and use OOP.

ciao,
 Emmanuele.

-- 
Emmanuele Bassi,
W: http://www.emmanuelebassi.net
B: http://log.emmanuelebassi.net




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