Search code examples
pythonmemorybuffergstreamer

How to copy and release a buffer in Gstreamer


I am working with the Python bindings for Gstreamer. I have a Buffer objects that I would like to copy and add to a queue so that it can be later processed by another thread. My application has a memory leak but I am not sure whether this is related to Gstreamer.

Copy the buffer

Currently I am copying the buffer like this:

gst_buffer_copied = gst_buffer.copy_deep()

Is this correct?

Release memory

Do I need to release the resource explicitly later? How can I do that? I tried with

gst_buffer_copied.remove_all_memory()

but I have Segmentation fault (core dumped) errors sometime. Not sure if that's right.


Solution

  • The gst_buffer_copied buffer should take ownership of it's own memory. So when the lifetime of this buffer ends it will take care of releasing it's memory.

    If you manually remove the memory chunks you should make sure no code in your application or pipeline is trying to access the buffer's memory after.

    So when you do that but the pipeline has not yet finished processing this buffer it will try to access the memory you have just freed causing the segmentation fault.