3
votes

I have a memory leak with gstreamer:

#include <iostream>
#include <string.h>
#include <glib.h>
#include <gst/gst.h>

using namespace std;

void info(const GstElement *const element)
{
        cout << "count: " << GST_OBJECT_REFCOUNT(element) << endl;
        cout << "disposing: " << GST_OBJECT_IS_DISPOSING(element) << endl;
}

int main()
{
    gst_init(NULL,NULL);
    GstElement *element = gst_pipeline_new("src");
    info(element);
    gst_object_unref(element);
    info(element);
    gst_deinit();
    return 0;
}

When I control my code with valgrind I obtain this result:

==9098== Command: ./test_gstreamer
==9098== 
count: 1
disposing: 0
count: 0
disposing: 0
==9098== 
==9098== HEAP SUMMARY:
==9098==     in use at exit: 1,364,118 bytes in 2,199 blocks
==9098==   total heap usage: 21,877 allocs, 19,678 frees, 3,899,417 bytes allocated
==9098== 
==9098== LEAK SUMMARY:
==9098==    definitely lost: 60 bytes in 1 blocks
==9098==    indirectly lost: 240 bytes in 10 blocks
==9098==      possibly lost: 543,952 bytes in 880 blocks
==9098==    still reachable: 819,866 bytes in 1,308 blocks
==9098==         suppressed: 0 bytes in 0 blocks
==9098== Rerun with --leak-check=full to see details of leaked memory
==9098== 
==9098== For counts of detected and suppressed errors, rerun with: -v
==9098== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)

Why doesn't gst_object_unref free all memory? Why does GST_OBJECT_IS_DISPOSING return false after gst_object_unref?

2

2 Answers

1
votes

Could you try changing your main to this:

gst_init(NULL,NULL);
GstElement *element = gst_pipeline_new("src");
info(element);
gst_element_set_state (element, GST_STATE_NULL);
gst_object_unref(element);
info(element);
return 0;

Think that might work.

1
votes

You should do what valgrind suggests: "Rerun with --leak-check=full to see details of leaked memory". See the answer here: http://gstreamer-devel.966125.n4.nabble.com/Valgrind-error-with-gstreamer-td4657149.html

The element is done disposing when gst_object_unref returns.