Re: [[gtkmm] technical question: GTKMM_LIFECYCLE]



Am 27.09.2002 20:10 schrieb(en) Murray Cumming:
MHL Schulze t-online de (Martin Schulze) wrote:
> Hi!
>
> In the process of wrapping gstreamer a few questions regarding
> the lifecylce management code of gtkmm popped up.
>
> In the current implementation of Gtk::Object the following behaviour
> doesn't seem to be 100% consistent (first scenario):
>
> - Why do we force a gtk_object_destroy() in the c++ instance's dtor
>    when it hasn't been manage()ed (i.e. referenced_ == true)?
>    Why don't we ensure that we simply remove all the references that
>    have been created from our c++ wrappers instead?

Because the C instance should be destroyed when the C++ instance is
deleted.
Why would you want a more complicated memory model?

> - gtkmm objects that were not manage()ed are reference counted non
>    the less. However, when the reference counter reaches zero the
>    c object is deleted but the c++ instance is not (only gobject_ is
>    set to 0).

No, whenever a C object is destroyed, the C++ instance _will_ be deleted.
It
might not be obvious how that happens, though I have tried to add verbose
and
repetitive comments about that kind of thing.

You must be wrong. It has always been possible to have gtkmm widgets
on the stack. This flexibility is the reason why the complication of
having the function manage() is necessary in the first place.

And sure enough, in Object::destroy_notify_() which gets executed
when the c instance dies, "delete this" is not reached when
"referenced_ == true" (i.e. when the object has not been manage()ed):

void Object::destroy_notify_()
{
  //Overriden.
  //GTKMM_LIFECYCLE

  #ifdef DEF_DEBUG_REFCOUNTING
g_warning("Gtk::Object::destroy_notify_: this=%10X, gobject_=%10X\n", this, gobject_);
  if(gobject_)
    g_warning("  gtypename=%s\n", G_OBJECT_TYPE_NAME(gobject_));
  #endif

  //Remember that it's been disposed (which only happens once):
//This also stops us from destroying it again in the destructor when it calls destroy_().
  gobject_disposed_ = true;

if(!cpp_destruction_in_progress_) //This function might have been called as a side-effect of destroy() when it called gtk_object_destroy().
  {
    if (!referenced_) //If it's manage()ed.
    {
      #ifdef DEF_DEBUG_REFCOUNTING
      g_warning("Gtk::Object::destroy_notify_: before delete this.\n");
      #endif
      delete this; //Free the C++ instance.
    }
else //It's not managed, but the C gobject_ just died before the C++ instance..
    {
      #ifdef DEF_DEBUG_REFCOUNTING
      g_warning("Gtk::Object::destroy_notify_: setting gobject_ to 0\n");
      #endif
      gobject_ = 0;
    }
  }

}


Please show me in the Code where the c++ instance is deleted when the
c instance dies when I'm wrong. I can't see it.


Regards,

  Martin



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