Unref Elements?

Nicolas Dufresne nicolas at ndufresne.ca
Thu Sep 21 00:31:59 UTC 2017


Le mercredi 20 septembre 2017 à 16:45 -0700, killerrats a écrit :
> when you use the *gst_bin_get_by_name ()* you unref them in a method just
> like in *bus_cb()*. I noticed in the tutorials you just unref the pipeline
> not any of the elements that are add to the pipeline. they don't go
> gst_object_unref(data.rtspsrc); or gst_object_unref(h264parse); or
> gst_object_unref(decodebin);. is that something you don't have to do or
> something I should be doing before I close?

The GObject comes with a model of floating references. When an object
is initially created, it has a ref counting of 1 but flagged as
floating. This is the case for all objects that subclass
GInitiallyUnowned instead of GObject.

When these objects are added to a container, the container will become
the new owner of the object. This ownership is taker through calling
g_object_ref_sink(). This method will transparently take a reference on
own object, and will take over an unowned object.

That is the reason why you don't need to unref the freshly created
GstElement that you pass to a GstBin/GstPipeline. You'll find the same
in GTK with GtkWidget added to any GtkContainer.

regards,
Nicolas


More information about the gstreamer-devel mailing list