tags:

views:

236

answers:

1

Hello,

I'm trying to embed a chartdrawer library that can only give me a bmp image in a buffer.

I'm loading this image and have to explicitly call delete on the newly created pixbuf and then call the garbage collector.

The drawing method is called each 50ms

calling the garbage collector is realy CPU consuming.

Is there a way to have only one pixbuf for the all process and thus not have to call gc?

Or am I doing everything wrong?

Thx in advance for any help

Raphaël

code:

  def draw(self, drawArea):

        #init bmp loader
        loader = gtk.gdk.PixbufLoader ('bmp')

        #get a bmp buffer
        chart = drawArea.outBMP2()

        #load this buffer
        loader.write(chart)
        loader.close()

        #get the newly created pixbuf        
        pixbuf = loader.get_pixbuf()

        #and load it in the gtk.Image
        self.img.set_from_pixbuf(pixbuf)

        del pixbuf
        gc.collect()
A: 

You don't need to call the garbage collector. Python is automatically garbage collected. At the end of your method, pixbuf falls out of scope (you also don't need "del pixbuf") and will be automatically garbage collected. So for starters, delete the last two lines of your method.

You might also want to just call your 'draw' method less often, if it's consuming too much CPU. In most applications I imagine the user could deal with updates every 200ms rather than every 50, if every 50ms means there's going to be a CPU problem.

Glyph
rapdum