<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML
dir=ltr><HEAD><TITLE>[gst-devel] Why do we call gst_object_unref() ?</TITLE>
<META content="text/html; charset=unicode" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.6001.18999"></HEAD>
<BODY>
<DIV dir=ltr id=idOWAReplyText52179>
<DIV dir=ltr><FONT color=#000000 size=2 face=Arial>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.</FONT></DIV>
<DIV dir=ltr><FONT size=2 face=Arial></FONT> </DIV>
<DIV dir=ltr><FONT size=2 face=Arial>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).</FONT></DIV>
<DIV dir=ltr><FONT size=2 face=Arial></FONT> </DIV>
<DIV dir=ltr><FONT size=2 face=Arial></FONT> </DIV>
<DIV dir=ltr><FONT size=2 face=Arial>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.</FONT></DIV>
<DIV dir=ltr><FONT size=2 face=Arial></FONT> </DIV>
<DIV dir=ltr><FONT size=2 face=Arial></FONT> </DIV>
<DIV dir=ltr><FONT size=2 face=Arial>Matt</FONT></DIV>
<DIV dir=ltr><FONT size=2 face=Arial></FONT> </DIV></DIV>
<DIV dir=ltr><BR>
<HR tabIndex=-1>
<FONT size=2 face=Tahoma><B>From:</B> gst_call_me_newbie()
[mailto:21stninjagod@gmail.com]<BR><B>Sent:</B> Sun 1/2/2011 1:43
AM<BR><B>To:</B> gstreamer-devel@lists.sourceforge.net<BR><B>Subject:</B>
[gst-devel] Why do we call gst_object_unref() ?<BR></FONT><BR></DIV>
<DIV><BR>
<P><FONT size=2>hi all,<BR><BR>I checked the meaning of the function
gst_object_unref() and got what it<BR>does but I could not get why do we call it
while the program is in<BR>execution.<BR><BR>for e.g this is a code snippet from
the application developer manual<BR>provided at the gstreamer's
site.<BR><BR>[some code here.....]<BR>bus = gst_pipeline_get_bus (GST_PIPELINE
(pipeline));<BR>gst_bus_add_watch (bus, my_bus_callback,
loop);<BR>gst_object_unref (bus);<BR>[some other code here.....]<BR><BR>so why
would someone want to unref the bus when we still need it in our<BR>program. If
I unref it and if somehow that would have been the last<BR>reference to the
object than object would surely be destroyed.<BR>so why should I call it. Please
enlighten me.<BR>Thanks<BR><BR><BR>--<BR>View this message in context: <A
href="http://gstreamer-devel.966125.n4.nabble.com/Why-do-we-call-gst-object-unref-tp3170699p3170699.html">http://gstreamer-devel.966125.n4.nabble.com/Why-do-we-call-gst-object-unref-tp3170699p3170699.html</A><BR>Sent
from the GStreamer-devel mailing list archive at
Nabble.com.<BR><BR>------------------------------------------------------------------------------<BR>Learn
how Oracle Real Application Clusters (RAC) One Node allows customers<BR>to
consolidate database storage, standardize their database environment,
and,<BR>should the need arise, upgrade to a full multi-node Oracle RAC
database<BR>without downtime or disruption<BR><A
href="http://p.sf.net/sfu/oracle-sfdevnl">http://p.sf.net/sfu/oracle-sfdevnl</A><BR>_______________________________________________<BR>gstreamer-devel
mailing list<BR>gstreamer-devel@lists.sourceforge.net<BR><A
href="https://lists.sourceforge.net/lists/listinfo/gstreamer-devel">https://lists.sourceforge.net/lists/listinfo/gstreamer-devel</A><BR></FONT></P></DIV></BODY></HTML>