<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
p.Sprechblasentext, li.Sprechblasentext, div.Sprechblasentext
        {mso-style-name:Sprechblasentext;
        mso-style-link:"Sprechblasentext Zchn";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
span.SprechblasentextZchn
        {mso-style-name:"Sprechblasentext Zchn";
        mso-style-priority:99;
        mso-style-link:Sprechblasentext;
        font-family:"Tahoma","sans-serif";}
span.EmailStyle21
        {mso-style-type:personal;
        font-family:"Arial","sans-serif";
        color:windowtext;}
span.EmailStyle22
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle23
        {mso-style-type:personal;
        font-family:"Arial","sans-serif";
        color:#1F497D;}
span.EmailStyle24
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle25
        {mso-style-type:personal-reply;
        font-family:"Arial","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#1F497D'>Can anybody else tell me if I’m handling the creation and destruction of the pipeline and its resources correctly? I’m trying to figure out if this is the cause of the apparent memory leak.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#1F497D'>Thanks,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#1F497D'>Jim<o:p></o:p></span></p><p class=MsoNormal><a name="_MailEndCompose"><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#1F497D'><o:p> </o:p></span></a></p><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> gstreamer-devel-bounces+restlessmindsstudio=gmail.com@lists.freedesktop.org [mailto:gstreamer-devel-bounces+restlessmindsstudio=gmail.com@lists.freedesktop.org] <b>On Behalf Of </b>Bernhard Graaf<br><b>Sent:</b> Wednesday, February 20, 2013 1:37 PM<br><b>To:</b> 'Discussion of the development of and with GStreamer'<br><b>Subject:</b> AW: Properly freeing resources<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span lang=EN-GB style='color:#1F497D'>Does it helps?<o:p></o:p></span></p><p class=MsoNormal><span lang=DE style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=DE style='color:#1F497D'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span lang=DE style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>Von:</span></b><span lang=DE style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> <a href="mailto:gstreamer-devel-bounces+bernhard.graaf=gmx.de@lists.freedesktop.org">gstreamer-devel-bounces+bernhard.graaf=gmx.de@lists.freedesktop.org</a> [<a href="mailto:gstreamer-devel-bounces+bernhard.graaf=gmx.de@lists.freedesktop.org">mailto:gstreamer-devel-bounces+bernhard.graaf=gmx.de@lists.freedesktop.org</a>] <b>Im Auftrag von </b>Jim<br><b>Gesendet:</b> Mittwoch, 20. Februar 2013 15:41<br><b>An:</b> 'Discussion of the development of and with GStreamer'<br><b>Betreff:</b> RE: Properly freeing resources<o:p></o:p></span></p></div></div><p class=MsoNormal><span lang=DE><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#1F497D'>Thanks I’ll give that a try!<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#1F497D'>Jim<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#1F497D'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> <a href="mailto:gstreamer-devel-bounces+restlessmindsstudio=gmail.com@lists.freedesktop.org">gstreamer-devel-bounces+restlessmindsstudio=gmail.com@lists.freedesktop.org</a> [<a href="mailto:gstreamer-devel-bounces+restlessmindsstudio=gmail.com@lists.freedesktop.org">mailto:gstreamer-devel-bounces+restlessmindsstudio=gmail.com@lists.freedesktop.org</a>] <b>On Behalf Of </b>Bernhard Graaf<br><b>Sent:</b> Tuesday, February 19, 2013 11:38 PM<br><b>To:</b> 'Discussion of the development of and with GStreamer'<br><b>Subject:</b> AW: Properly freeing resources<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span style='color:#1F497D'>I’ve found a small mismatch:<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>The ‘gst_object_unref(streamData->bus)’ should be called after init the signal bus, not before sending a new video.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>Hope that helps<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>Bernhard<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span lang=DE style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>Von:</span></b><span lang=DE style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> <a href="mailto:gstreamer-devel-bounces+bernhard.graaf=gmx.de@lists.freedesktop.org">gstreamer-devel-bounces+bernhard.graaf=gmx.de@lists.freedesktop.org</a> [<a href="mailto:gstreamer-devel-bounces+bernhard.graaf=gmx.de@lists.freedesktop.org">mailto:gstreamer-devel-bounces+bernhard.graaf=gmx.de@lists.freedesktop.org</a>] <b>Im Auftrag von </b>Jim<br><b>Gesendet:</b> Dienstag, 19. Februar 2013 19:03<br><b>An:</b> <a href="mailto:gstreamer-devel@lists.freedesktop.org">gstreamer-devel@lists.freedesktop.org</a><br><b>Betreff:</b> Properly freeing resources<o:p></o:p></span></p></div></div><p class=MsoNormal><span lang=DE><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Hi Everyone,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>I’ve been watching the memory usage of my C application that’s using Gstreamer 0.10.36 and notice the allocated memory (according to the top command) keeps increasing slowly over time. This is only happening while Gstreamer is playing a video. When the application is idle, not using Gstreamer, the memory usage does not increase. I’m wondering if I’m doing something wrong with how I’m using the Gstreamer library.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>The application is basically a media player that provides the user with a list of videos to play. At any time the user can switch to a different video. Every time it starts playing another video, it goes through the following initialization:<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  // Create the pipeline and its elements<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  streamData->pipeline = gst_pipeline_new("my-pipeline");<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  streamData->fileSrc = gst_element_factory_make("filesrc", "fileSrc");<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  streamData->demux = gst_element_factory_make("tsdemux", "demux");<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  streamData->videoQueue = gst_element_factory_make("queue", "videoQueue");<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  streamData->audioQueue = gst_element_factory_make("queue", "audioQueue");<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  streamData->videoDecoder = gst_element_factory_make("vpudec", "videoDecoder");<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  streamData->videoSink = gst_element_factory_make("mfw_v4lsink", "videoSink");<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  streamData->audioDecoder = gst_element_factory_make("mfw_mp3decoder", "audioDecoder");<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  streamData->volumeFilter = gst_element_factory_make("volume", "volume");<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  streamData->audioSink = gst_element_factory_make("alsasink", "audioSink");<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  if (!streamData->pipeline || !streamData->fileSrc || !streamData->demux || !streamData->videoQueue ||<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>      !streamData->audioQueue || !streamData->videoDecoder || !streamData->videoSink ||<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>      !streamData->audioDecoder || !streamData->volumeFilter || !streamData->audioSink)<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  {<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>    g_printerr("Not all elements could be created.\n");<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>    return;<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  }<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  gst_bin_add_many(GST_BIN(streamData->pipeline), streamData->fileSrc, streamData->demux, streamData->videoQueue,<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>                   streamData->audioQueue, streamData->videoDecoder, streamData->videoSink, streamData->audioDecoder,<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>                   streamData->volumeFilter, streamData->audioSink, NULL);<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  if (!gst_element_link(streamData->fileSrc, streamData->demux))<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  {<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>    g_printerr("Elements could not be linked\n");<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>    gst_object_unref(streamData->pipeline);<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>    return;<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  }<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  if (!gst_element_link_many(streamData->videoQueue, streamData->videoDecoder, streamData->videoSink, NULL))<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  {<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>    g_printerr("Elements could not be linked\n");<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>    gst_object_unref(streamData->pipeline);<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>    return;<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  }<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  if (!gst_element_link_many(streamData->audioQueue, streamData->audioDecoder, streamData->volumeFilter, streamData->audioSink, NULL))<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  {<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>    g_printerr("Elements could not be linked\n");<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>    gst_object_unref(streamData->pipeline);<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>    return;<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  }<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  g_object_set(G_OBJECT(streamData->videoQueue), "max-size-buffers", 0, NULL);<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  g_object_set(G_OBJECT(streamData->videoQueue), "max-size-time", 0, NULL);<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  g_object_set(G_OBJECT(streamData->audioQueue), "max-size-buffers", 0, NULL);<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  g_object_set(G_OBJECT(streamData->audioQueue), "max-size-time", 0, NULL);<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  g_signal_connect(streamData->demux, "pad-added", G_CALLBACK(pad_added_handler), streamData);<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  // Retrieve pipeline signal bus<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  streamData->bus = gst_pipeline_get_bus(GST_PIPELINE(streamData->pipeline));<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  streamData->busWatchId = gst_bus_add_watch(streamData->bus, (GstBusFunc)handle_message, streamData);<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Before switching to a another video, the following cleanup is done:<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  gst_object_unref(streamData->bus);<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  gst_element_set_state(streamData->pipeline, GST_STATE_NULL);<o:p></o:p></span></p><p class=MsoNormal style='margin-left:.5in'><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>  gst_object_unref(streamData->pipeline);<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Is this all the cleanup I need to do before creating a new pipeline or is there something else?<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Thanks,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Jim<o:p></o:p></span></p></div></body></html>