Re: glib ref counting problem



Stefan Kost wrote:
hi hi,

hope that someone can enlighten me with my understanding of the gobject
ref-counting regarding to object destruction.

I have a gobject called BtSong. Upon construction it creates instances of
BtPattern, BtSetup and so on where it passes itself along.
Thus each child object now holds a reference to the BtSong object.
When the application that initialy created the BtSong instance is done, it would
like to destroy the object with all the accosiated ressources. It therefore
calles g_object_unref(song);.
Now the problem is that this only decreases the ref-count from e.g. 5 to 4,
because the child objects still have their reference on it.
Therefore the dispose() routine is not called and therefore the BtSong does not
release (unref) its child objects.

Apparently I have not yet understand the gobject system fully :-(
Can anyone tell me how to do it properly?

Do you need BtPattern etc to ref BtSong?

Unref BtPattern etc in BtSong dispose handler, and in BtPattern etc
dispose handlers, unref BtSong.



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