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 son 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);.

If BtSong is the "owner" of BtPattern and BtSetup, then BtSong should
simply hold the initial reference on BtSetup and BtPattern (i.e. every
object is "born" with a `ref_count = 1'. Thus in bt_song_finalize(),
BtSong will release its reference on BtPattern and BtSetup, leading to
their destruction. If for example, BtPattern is needed after BtSong's
destruction, then the code which requires its existance, should hold
a reference to BtPattern and release it when it is no longer needed.

HTH,
                                        -Tristan




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