AppSink consumes lot's of memory. How to control memory consumption?
Nicolas Dufresne
nicolas at ndufresne.ca
Fri Sep 15 14:23:36 UTC 2023
Le vendredi 15 septembre 2023 à 12:26 +0300, Антон Шаров via gstreamer-devel a
écrit :
> Hi. Thank you very much for reply.
>
> I’ve added as you suggested, but still no luck, still saw-tooth behaviour:
> var appSink = new AppSink("appsink_{CaptureConfig.CameraId}");
> appSink.NewSample += AppSinkNewSample;
> appSink.EmitSignals = true;
> appSink.Drop = true;
> appSink.MaxBuffers= 10;
>
> I’ve tried to isolate appsink, used multifilesink instead, and there was no
> memory consumption.
> So there is definitely problems in appsink, and most obvious solutions seems
> not to be working...
>
> > Пятница, 15 сентября 2023, 2:39 +03:00 от Michael Gruner
> > <michael.gruner at ridgerun.com>:
> >
> > Appsink has an internal queue. If your app does not consume samples fast
> > enough, buffers will start accumulating in the queue.
> >
> > You can limit the amount of buffers that the internal queue can hold using
> > the "max-buffers" and "drop" properties. For example: "appsink max-
> > buffers=10 drop=true".
> >
> > > On 14 Sep 2023, at 17:32, Антон Шаров via gstreamer-devel
> > <gstreamer-devel at lists.freedesktop.org> wrote:
> > >
> > > Hi.
> > >
> > > Consider following pipeline:
> > > rtspsrc ! rtph264depay ! h264parse ! tee name=vi vi. ! queue !
> > splitmuxsink vi. ! queue ! avdec_h264 ! jpegenc ! apsink
> > >
> > > Appsink config and NewSample handler is below. My problem is that it
> > consumes lot’s of (unmanaged) memory.
> > > There is no leak, it works ok, after .net GC run memory lower to normal
> > values and then grows again. It looks like
> > > saw-tooth. I’ve tried to limit max-buffers (set it to 100 or 1), drop =
> > true but it seems that nothing works. Memory profiler shows smth like 30K
> > instances of Gst.Memory holds 1.5Gb of unmanaged (in terms of .net) memory.
> > Aftre GC collect, it seems to collect some of these instances and release
> > some unmanaged memory (say it lowers 10 times). Again, there is no leeks, I
> > just want to lower memory consumption of appsink element.
I believe recent C# GC allow you to do explicit unref (nullifying the object) to
workaround the issue. The GC have no idea about the size of the object/buffer,
so it does not prioritize it.
> > >
> > > Any ideas how to achieve that?
> > >
> > > Thanks in advance.
> > >
> > >
> > > Appsink code:
> > >
> > > var appSink = new AppSink("appsink_{CaptureConfig.CameraId}");
> > > appSink.NewSample += AppSinkNewSample;
> > > appSink.EmitSignals = true;
> > >
> > > private void AppSinkNewSample(object o, NewSampleArgs args)
> > > {
> > > if (o is AppSink aps)
> > > {
> > > using (var sample = aps.PullSample())
> > > {
> > > using (var buf = sample.Buffer)
> > > {
> > > SomeStuff(buf);
> > > }
> > > }
> > > }
> > > }
> > >
> > >
> > >
>
>
> --
> С Уважением,
> Шаров Антон
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20230915/e3670029/attachment.htm>
More information about the gstreamer-devel
mailing list