- }
-
- virtual ~wxToolBarTool()
- {
- if ( IsControl() && !m_item )
- {
- // if we're a control which is not currently attached to the
- // toolbar (as indicated by NULL m_item), we must undo the extra
- // reference we added in DoDeleteTool()
- g_object_unref(GetControl()->m_widget);
- }
+ // Hold a reference to keep control alive until DoInsertTool() is
+ // called, or if RemoveTool() is called (see DoDeleteTool)
+ g_object_ref(control->m_widget);
+ // release reference when gtk_widget_destroy() is called on control
+ g_signal_connect(
+ control->m_widget, "destroy", G_CALLBACK(g_object_unref), NULL);