[gtkmm] "manage" and Glib::RefPtr



Just a theoretical question (which might solve some memory managaement problems if possible):

Is it possible to write a manage_ref 'function' which would ...
- destroy the widget once no RefPtr (or C ref) to it is left
- not get the widget destroyed once it's container is destroyed but unrefed (unlike manage, IIRC manage does set some gtk+ flag which enables unconditional destruction)

This would allow code like
{ Glib::RefPtr<Gtk::Window> w=manage_ref(new Gtk::Window(...));
   ...
  { Glib::RefPtr<Gtk::Label> l=manage_ref(new Gtk::Label("test"));
    w.add(l);
  }
  ...
  // w leavess the scope
  // => w gets destroyed, the Label unrefed (and then destroyed)
}
and if I understand correctly this would solve the destroy vs. unref problem with widgets. IIRC this would also not force us to use RefPtrs for any function arguments (function arguments outlive the call).

Correct me if I'm wrong
   Christof





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