GNOME Bugzilla – Bug 637746
gst-python memory leak with python element
Last modified: 2012-10-28 22:44:26 UTC
Running this code i get a memory leak: #!/usr/bin/python import pygst pygst.require("0.10") import gst import gobject class Leaker(gst.Element): #source pad (template): we send buffers forward through here _srctemplate = gst.PadTemplate ('src', gst.PAD_SRC, gst.PAD_ALWAYS, gst.caps_new_any()) #sink pad (template): we recieve buffers from our sink pad _sinktemplate = gst.PadTemplate ('sink', gst.PAD_SINK, gst.PAD_ALWAYS, gst.caps_new_any()) #register our pad templates __gsttemplates__ = (_srctemplate, _sinktemplate) def __init__(self): gst.Element.__init__(self) #source pad, outgoing data self.srcpad = gst.Pad(self._srctemplate) #sink pad, incoming data self.sinkpad = gst.Pad(self._sinktemplate) self.sinkpad.set_setcaps_function(self._sink_setcaps) self.sinkpad.set_chain_function(self._sink_chain) #make pads available self.add_pad(self.srcpad) self.add_pad(self.sinkpad) def _sink_setcaps(self, _pad, _caps): # We negotiate our capabilities here, this function is called # as we accept anything, we just say yes we can handle the # incoming data. return True def _sink_chain(self, _pad, buffer): return self.srcpad.push(buffer.copy()) gobject.type_register(Leaker) pipeline = gst.Pipeline() fakesrc = gst.element_factory_make('fakesrc') filter = Leaker() fakesink = gst.element_factory_make('fakesink') pipeline.add(fakesrc) pipeline.add(filter) pipeline.add(fakesink) fakesrc.link(filter) filter.link(fakesink) pipeline.set_state(gst.STATE_PLAYING) loop = gobject.MainLoop() loop.run()
> def _sink_chain(self, _pad, buffer): > return self.srcpad.push(buffer.copy()) Try: return self.srcpad.push(buffer) In C the semantics are so that you pass ownership of the buffer ref to gst_pad_push().
Closing this bug report as no further information has been provided. Please feel free to reopen this bug if you can provide the information asked for. Thanks!
With the solution proposed in comment #1 there is no leak. But what i mean is that probably there is a reference counting problem when using buffer.copy.
Possible, but sounds unlikely to me. What if you force garbage collection every now and then?
I called gc.collect every 1000 buffers and the memory continued rising.
can you reproduce the problem in recent GStreamer ?
Miguel, any chance you can update us here?
pygst is deprecated anyway, so let's just close this.