Skip to main content
1 of 4

Grk::manage() solves specific problem of lifetime management for hierarchies of widgets. And it solves it well.

Smart pointers (shared_ptr in particular) have broader application range, and therefore will be less efficient when used to address the same problem. Lifetime management for hierarchies of widgets can be solved with shared_ptr, but it will be:

  • not as concise as using manage() (as you pointed out yourself);
  • using shared_ptr's will introduce memory overhead as shared_ptr memory footprint is going to contribute to your widget's size (as opposed to manage(), which as far as I'm aware uses variables and references, such as, say Gtk::Object.referenced_, that are in your Widget already, no matter you use manage() on it or not); so if you have lots of Widgets - it might become an issue worth considering;
  • not as mainstream as using manage() in Gtk.

As of your concern of using shared_ptr because it is part of C++ Standard, while Gtk::manage is not - I'm not sure it is going to be a game changer, as by not using manage() you don't cut your dependency from Gtk anyways.

I would rather leverage native Gtk API, for sake of clarity and efficiency.

p.s. there is actually GLib::RefPtr, which can allow you to manage lifetime of Widgets in a manual way. Again, as it is a feature native to GLib it leverages built-in facilities of Glib::ObjectBase, and therefore more efficient then shared_ptr for certain applications.