Restarting the pipeline all the time will cause memory leaks in the gstreamer

Hello everyone,

I need to restart the pipeline constantly. I find that the memory will rise (memory leak?), I have tried many versions of gstreamer and deepstream, including Gstreamer1.14.5, 1.18.2, 1.20.3, 1.20.4 DeepStream 4.0, 5.0, and 5.1. The following is a demo

test.c
need to change the location of rtspsrc

#include <locale.h>
#include <glib.h>
#include <gst/gst.h>
#include <glib-unix.h>
#include <stdio.h>
#include <stdbool.h>
static gboolean
quit_loop (gpointer data)
{
    g_print("quit \n");
    GMainLoop *loop = (GMainLoop*)data;
    g_main_loop_quit(loop);
    return false;
}
int main(int argc, char *argv[]){
    /* Initialize GStreamer */
    gst_init (&argc, &argv);
    while (1){
        GMainLoop *mainloop = g_main_loop_new(NULL, FALSE);
        GstElement* pipeline =
        gst_parse_launch
        ("rtspsrc location=rtsp://admin:passwd@ip ! parsebin ! h264parse ! avdec_h264 ! fakesink ",
        NULL);
        g_print("playing\n");
        gst_element_set_state (pipeline, GST_STATE_PLAYING);

        g_timeout_add_seconds(30,(GSourceFunc)quit_loop,mainloop);
        g_print("run\n");
        g_main_loop_run(mainloop);
        gst_element_set_state(pipeline,GST_STATE_NULL);
        g_print("unref \n");
        gst_object_unref(pipeline);
        g_main_loop_unref(mainloop);
    }
    return 0;
}

MakeFile

CC	:= gcc
LIBS	:= $(shell pkg-config --libs --cflags gstreamer-1.0 )
test: test.c
	"$(CC)" $^ $(LIBS) -o $@

There are two problems in the above code.

  1. After the pipe is closed( code : “gst_element_set_state(pipeline,GST_STATE_NULL)”), the memory is not reduced.
  2. Constantly re creating and closing the pipeline will cause the memory to increase all the time.According to different element, the number of Memory can vary from <10M to >100M over a period of time.

This problem can be reproduced using any element and any version of Gstreamer/DeepStream,This problem occurs even when using Rust.(Python and java have GC, which has no reference significance.)This problem is 100% recurrent

Same question link:

This problem will make it impossible for me to restart a pipeline in the program for many times, and I can only restart the program every time.

Is my method of use wrong?
Look forward to your reply, thank you

There is no update from you for a period, assuming this is not an issue anymore. Hence we are closing this topic. If need further support, please open a new one.
Thanks

GStreamer is an open source project. You can report the GStreamer memory leak issue to GStreamer community. Contributing to GStreamer. This is DeepStream forum.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.