[gst-devel] Why do we call gst_object_unref() ?

Gruenke, Matt mgruenke at Tycoint.com
Sun Jan 2 08:43:46 CET 2011


It's used to perform reference counting.  Each use or user of an object should be counted.  When that count goes to 0, then it means the object is no longer needed and the resources it occupies can be reclaimed.  If you see an object being unref'd that should continue to exist, then you should check up on who is resposible for keeping a count on it, after the unref in question.
 
The reason this is necessary during program execution is that numerous short-lived objects are created.  If these are never deallocated, then a program's memory usage would continually grow.  Ref-counting is sometimes described as a lesser form of garbage collection, and is commonly used in cases where there's not necessarilly a clear relationship between consumers and producers of objects.  Be warned that ref counting fails in the case of circular references (weak refs can sometimes be used to avoid these scenarios).
 
 
BTW, this is complicated by the concept of "parenting", where exclusive ownership of an object is asserted.  I encourage you to look for details about all of this in the GLib docs, as I'm sure it must be described in there at length.
 
 
Matt
 

________________________________

From: gst_call_me_newbie() [mailto:21stninjagod at gmail.com]
Sent: Sun 1/2/2011 1:43 AM
To: gstreamer-devel at lists.sourceforge.net
Subject: [gst-devel] Why do we call gst_object_unref() ?




hi all,

I checked the meaning of the function gst_object_unref() and got what it
does but I could not get why do we call it while the program is in
execution.

for e.g this is a code snippet from the application developer manual
provided at the gstreamer's site.

[some code here.....]
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
gst_bus_add_watch (bus, my_bus_callback, loop);
gst_object_unref (bus);
[some other code here.....]

so why would someone want to unref the bus when we still need it in our
program. If I unref it and if somehow that would have been the last
reference to the object than object would surely be destroyed.
so why should I call it. Please enlighten me.
Thanks


--
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/Why-do-we-call-gst-object-unref-tp3170699p3170699.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
gstreamer-devel mailing list
gstreamer-devel at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gstreamer-devel


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20110102/a4842ac2/attachment.htm>


More information about the gstreamer-devel mailing list