MattsProjects / pylon_gstreamer

A robust integration of Basler's Pylon API with GStreamer. Delivers applications as ready-to-run standalone compiled executables (gst-launch-1.0 is not needed). Designed for reliability and easy access to performance optimizations. Note: This is not a plugin. It is an intergration using GStreamer's GstAppSrc element.
Apache License 2.0
29 stars 18 forks source link

Fix memory leak in retrieve_image #15

Closed TobiasSchaffner closed 1 month ago

TobiasSchaffner commented 4 years ago

I think that there is a memory leak in retrieve_image. After running your project for more than a couple of hours I noticed that the application was eating up gigabytes of ram.

The problem seems to be how you handle the image buffer. I am not an gstreamer expert but I think somebody has to call gst_buffer_unref on this when the buffer is not needed anymore (somewhere after the signal emit).

You could do this by hand but I decided to use the gst_app_src_push_buffer method which takes ownership of the buffer and takes care that the buffer is unrefed implicitly.

MattsProjects commented 4 years ago

Hi Tobias! Thank you for picking this up! I see, yes you're correct about the implementation. I should do an unref when pushing via the signal. But I have not seen a memory leak like this before... could you tell me the hw platform/OS you're using, and also the pipeline you're testing with? Just so I don't forget (and to learn), I'd like to try and reproduce this before I pull in. Thank you again for spotting this! -Matt

TobiasSchaffner commented 4 years ago

Hello Matt,

I am working on a x86_64 Debian Stretch with a Basler daA1920-30um camera.

The pipeline looks like this: queue, videoscale, capsfilter, videoconvert, x264enc, udpsink

Ask anytime if you need more information!

Greetings, Tobias