Object Lifetime Management

Since this may be many people's first interaction with Bonobo, and since Bonobo's lifetime management may not be apparent at first, this section is here to provide you with the correct way of managing the lifetime of your GNOME File Selector.

The full example in the next section also illustrates the correct behaviour.

The Bonobo::Control

Managing the Bonobo::Control part of the GNOME File Selector is easy. When you add the control to its parent window, you pass your reference onto the container (it gets "sunk" in GTK+ terms). This means that you do not need to unref the control, as long as the toplevel window it is in gets destroyed (which you may have to do manually).

The Bonobo::EventSource

The Bonobo::EventSource that was ::queryInterface()'d for needs to be released by you when you are done with it. You also need to remove your Bonobo::Listener from it.

Example 9. Cleaning Up Your EventSource


	    Bonobo_EventSource es;
	    Bonobo_EventSource_ListenerId id;

	    Bonobo_EventSource_removeListener (es, id, ev);
	  

The Bonobo::Listener

You need to simply unref your BonoboListener.

Example 10. Unref'ing the BonoboListener


	    BonoboListener *listener;

	    bonobo_object_unref (BONOBO_OBJECT (priv->listener));
	  

The Bonobo::PropertyBag

If you manually obtained the PropertyBag from the file selector control, you need to unref that, too.

Example 11. Unref'ing the Bonobo::PropertyBag


	    Bonobo_PropertyBag pb;

	    bonobo_object_release_unref (pb, ev);
	  

Note

Notice that the pb above is a Bonobo_Unknown (CORBA Object), while the listener is a BonoboObject (GTK+ object).