Properly freeing resources

Jim restlessmindsstudio at gmail.com
Fri Feb 22 15:32:13 PST 2013


As I continue to try and figure out what is causing this apparent memory
leak in my application, I decided to perform a sanity check by monitoring
system memory while just running gst-launch.

I'm finding that even gst-launch is resulting in a memory drain. I'm
watching the used and free memory available to the system and in 15 minutes,
used memory went from 22MB (before launching gst-launch) to 238MB and it
continues to grow at a fairly steady rate. If I look at the allocated memory
for gst-launch, it's at 88MB. Where is all this free memory going?

Is this normal behavior for GStreamer?

By the way, the command line I'm using is: gst-launch playbin2
uri=file:///video.ts

Thanks,
Jim

-----Original Message-----
From:
gstreamer-devel-bounces+restlessmindsstudio=gmail.com at lists.freedesktop.org
[mailto:gstreamer-devel-bounces+restlessmindsstudio=gmail.com at lists.freedesk
top.org] On Behalf Of Tim-Philipp Müller
Sent: Friday, February 22, 2013 12:41 PM
To: gstreamer-devel at lists.freedesktop.org
Subject: Re: Properly freeing resources

On Wed, 2013-02-20 at 07:41 -0700, Jim wrote:

Hi,

your code looks mostly ok.

>   streamData->videoDecoder = gst_element_factory_make("vpudec",
> "videoDecoder");
>   streamData->videoSink = gst_element_factory_make("mfw_v4lsink",
> "videoSink");
>   streamData->audioDecoder =
> gst_element_factory_make("mfw_mp3decoder", "audioDecoder");

I would check these elements first, if they free all resources correctly
when being shut down and/or being shut down during playback.


>   g_object_set(G_OBJECT(streamData->videoQueue), "max-size-time", 0,
NULL);
>   g_object_set(G_OBJECT(streamData->audioQueue), "max-size-time", 0, 
> NULL);

You want (guint64)0 here.

>   g_signal_connect(streamData->demux, "pad-added", 
> G_CALLBACK(pad_added_handler), streamData);

What do you do in the pad_added_handler? Are you sure you are not leaking
any references there?

>   // Retrieve pipeline signal bus
>   streamData->bus =
> gst_pipeline_get_bus(GST_PIPELINE(streamData->pipeline));
>   streamData->busWatchId = gst_bus_add_watch(streamData->bus,
> (GstBusFunc)handle_message, streamData);

FWIW, you don't have to keep a ref to the bus around if you don't need it,
you can just unref it right here and there after adding the watch if you
want to.

> Before switching to a another video, the following cleanup is done:
> 
>   gst_object_unref(streamData->bus);
>   gst_element_set_state(streamData->pipeline, GST_STATE_NULL);
>   gst_object_unref(streamData->pipeline);

You will also need to

  to g_source_remove (streamData->busWatchId)

Cheers
 -Tim


_______________________________________________
gstreamer-devel mailing list
gstreamer-devel at lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel



More information about the gstreamer-devel mailing list