After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 637746 - gst-python memory leak with python element
gst-python memory leak with python element
Status: RESOLVED INCOMPLETE
Product: GStreamer
Classification: Platform
Component: gst-python
0.10.20
Other Linux
: Normal normal
: NONE
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2010-12-21 14:27 UTC by Miguel Angel Cabrera Moya
Modified: 2012-10-28 22:44 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Miguel Angel Cabrera Moya 2010-12-21 14:27:03 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()
Comment 1 Tim-Philipp Müller 2011-10-29 14:59:45 UTC
>     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().
Comment 2 Tobias Mueller 2012-02-01 00:31:32 UTC
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!
Comment 3 Miguel Angel Cabrera Moya 2012-02-02 11:04:00 UTC
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.
Comment 4 Tim-Philipp Müller 2012-02-02 11:35:39 UTC
Possible, but sounds unlikely to me. What if you force garbage collection every now and then?
Comment 5 Miguel Angel Cabrera Moya 2012-02-02 15:39:41 UTC
I called gc.collect every 1000 buffers and the memory continued rising.
Comment 6 Akhil Laddha 2012-06-18 16:45:39 UTC
can you reproduce the problem in recent GStreamer ?
Comment 7 Tobias Mueller 2012-10-28 22:30:35 UTC
Miguel, any chance you can update us here?
Comment 8 Tim-Philipp Müller 2012-10-28 22:44:26 UTC
pygst is deprecated anyway, so let's just close this.