Memory leakage in matplotlib 1.0.1 with wx 2.8.11.0

I’m having a memory leakage using matplotlib 1.0.1 with wx 2.8.11.0, on windows XP.

To reproduce, I used the sample from here: http://matplotlib.sourceforge.net/examples/animation/dynamic_image_wxagg2.html and deleted most of the significant lines (see below). I only create a canvas but I don’t create any axes, nor plot any data.

The only thing I do is draw() on a timer event. This makes my process grow about 6Mbyte per minute.

Is this reproduced in other environments? Any ideas on how to resolve this?

Thanks,
Oren

“”"

Copyright © 2003-2005 Jeremy O’Donoghue and others

License: This work is licensed under the PSF. A copy should be included
with this source code, and is also available at
http://www.python.org/psf/license.html

“”"
import sys, time, os, gc

import matplotlib
matplotlib.use(‘WXAgg’)

from matplotlib import rcParams
import numpy as npy

import matplotlib.cm as cm

from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
from matplotlib.backends.backend_wx import NavigationToolbar2Wx

from matplotlib.figure import Figure
from wx import *

TIMER_ID = NewId()

class PlotFigure(Frame):

def __init__(self):
    Frame.__init__(self, None, -1, "Test embedded wxFigure")

    self.fig = Figure((1,1), 50, facecolor='.95')
    self.canvas = FigureCanvasWxAgg(self, -1, self.fig)

    # Now put all into a sizer
    sizer = wx.BoxSizer(wx.VERTICAL)
    # This way of adding to sizer allows resizing
    sizer.Add(self.canvas, 1, wx.LEFT|wx.TOP|wx.GROW)
    self.SetSizer(sizer)

    self.Fit()

    self._price_ax = self.fig.add_subplot(111)
   

    wx.EVT_TIMER(self, TIMER_ID, self.onTimer)
    self.t = wx.Timer(self, TIMER_ID)
    self.t.Start(1000)

def onTimer(self, evt):
    self.canvas.draw()

if name == ‘main’:
app = PySimpleApp()
frame = PlotFigure()
# Initialise the timer - wxPython requires this to be connected to

# the receiving event handler
t = Timer(frame, TIMER_ID)
t.Start(100)

frame.Show()
app.MainLoop()

I have now tested this with version 1.1.0svn from the trunk of the dev repository. I believe this version contains Michael Droettboo’s patch for pyCXX. (
https://sourceforge.net/tracker/index.php?func=detail&aid=3115633&group_id=3180&atid=103180 )

Unfortunately the leak is still evident in the small script I’ve attached. Again, please note that this script has no axes, plots, or drawn components, only an empty canvas that is being redrawn and causes the memory growth.

Any ideas how to resolve this or further debug this?

Thanks for your help,
Oren

···

On Mon, Apr 11, 2011 at 6:37 PM, Oren Gampel <oren@…3526…> wrote:

I’m having a memory leakage using matplotlib 1.0.1 with wx 2.8.11.0, on windows XP.

To reproduce, I used the sample from here: http://matplotlib.sourceforge.net/examples/animation/dynamic_image_wxagg2.html and deleted most of the significant lines (see below). I only create a canvas but I don’t create any axes, nor plot any data.

The only thing I do is draw() on a timer event. This makes my process grow about 6Mbyte per minute.

Is this reproduced in other environments? Any ideas on how to resolve this?

Thanks,
Oren

“”"

Copyright (C) 2003-2005 Jeremy O’Donoghue and others

License: This work is licensed under the PSF. A copy should be included
with this source code, and is also available at
http://www.python.org/psf/license.html

“”"
import sys, time, os, gc

import matplotlib
matplotlib.use(‘WXAgg’)

from matplotlib import rcParams
import numpy as npy

import matplotlib.cm as cm

from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
from matplotlib.backends.backend_wx import NavigationToolbar2Wx

from matplotlib.figure import Figure
from wx import *

TIMER_ID = NewId()

class PlotFigure(Frame):

def __init__(self):
    Frame.__init__(self, None, -1, "Test embedded wxFigure")

    self.fig = Figure((1,1), 50, facecolor='.95')
    self.canvas = FigureCanvasWxAgg(self, -1, self.fig)


    # Now put all into a sizer
    sizer = wx.BoxSizer(wx.VERTICAL)
    # This way of adding to sizer allows resizing
    sizer.Add(self.canvas, 1, wx.LEFT|wx.TOP|wx.GROW)
    self.SetSizer(sizer)


    self.Fit()

    self._price_ax = self.fig.add_subplot(111)
   

    wx.EVT_TIMER(self, TIMER_ID, self.onTimer)
    self.t = wx.Timer(self, TIMER_ID)
    self.t.Start(1000)



def onTimer(self, evt):
    self.canvas.draw()

if name == ‘main’:
app = PySimpleApp()
frame = PlotFigure()
# Initialise the timer - wxPython requires this to be connected to

# the receiving event handler
t = Timer(frame, TIMER_ID)
t.Start(100)

frame.Show()
app.MainLoop()

The repository is now on github, so if you want the very latest, you
should get it from here:

(We haven’t done a terribly good job of advertising that change).
I’m not seeing any leak myself with your script with matplotlib HEAD
plus this pull request:
so we may be getting to the bottom of this type of leak.
Mike

···

https://github.com/matplotlib/matplotlib

https://github.com/matplotlib/matplotlib/pull/89

I have now tested this with version 1.1.0svn from the
trunk of the dev repository. I believe this version contains Michael
Droettboo’s patch for pyCXX. ( https://sourceforge.net/tracker/index.php?func=detail&aid=3115633&group_id=3180&atid=103180
)

Unfortunately the leak is still evident in the small script I’ve
attached. Again, please note that this script has no axes, plots, or
drawn components, only an empty canvas that is being redrawn and causes
the memory growth.

Any ideas how to resolve this or further debug this?

Thanks for your help,

Oren

On Mon, Apr 11, 2011 at 6:37 PM, Oren Gampel
<oren@…3526…>
wrote:

I’m having a memory leakage using matplotlib 1.0.1
with wx 2.8.11.0, on windows XP.

To reproduce, I used the sample from here: http://matplotlib.sourceforge.net/examples/animation/dynamic_image_wxagg2.html
and deleted most of the significant lines (see below). I only create a
canvas but I don’t create any axes, nor plot any data.

The only thing I do is draw() on a timer event. This makes my process
grow about 6Mbyte per minute.

Is this reproduced in other environments? Any ideas on how to resolve
this?

Thanks,

Oren

“”"

Copyright (C) 2003-2005 Jeremy O’Donoghue and others

License: This work is licensed under the PSF. A copy should be included

with this source code, and is also available at

[http://www.python.org/psf/license.html](http://www.python.org/psf/license.html)

“”"

import sys, time, os, gc

import matplotlib

matplotlib.use(‘WXAgg’)

from matplotlib import rcParams

import numpy as npy

import matplotlib.cm as cm

from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg

from matplotlib.backends.backend_wx import NavigationToolbar2Wx

from matplotlib.figure import Figure

from wx import *

TIMER_ID = NewId()

class PlotFigure(Frame):

def __init__(self):

    Frame.__init__(self, None, -1, "Test embedded wxFigure")



    self.fig = Figure((1,1), 50, facecolor='.95')

    self.canvas = FigureCanvasWxAgg(self, -1, self.fig)

    # Now put all into a sizer

    sizer = wx.BoxSizer(wx.VERTICAL)

    # This way of adding to sizer allows resizing

    sizer.Add(self.canvas, 1, wx.LEFT|wx.TOP|wx.GROW)

    self.SetSizer(sizer)

    self.Fit()



    self._price_ax = self.fig.add_subplot(111)

   



    wx.EVT_TIMER(self, TIMER_ID, self.onTimer)

    self.t = wx.Timer(self, TIMER_ID)

    self.t.Start(1000)



def onTimer(self, evt):

    self.canvas.draw()

if name == ‘main’:

app = PySimpleApp()

frame = PlotFigure()

# Initialise the timer - wxPython requires this to be connected to

# the receiving event handler

t = Timer(frame, TIMER_ID)

t.Start(100)



frame.Show()

app.MainLoop()


Benefiting from Server Virtualization: Beyond Initial Workload Consolidation – Increasing the use of server virtualization is a top
priority.Virtualization can reduce costs, simplify management, and improve application availability and disaster protection. Learn more about boosting the value of server virtualization. _______________________________________________
Matplotlib-users mailing list
http://p.sf.net/sfu/vmware-sfdev2dev


Matplotlib-users@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/matplotlib-users

-- Michael Droettboom
Science Software Branch
Space Telescope Science Institute
Baltimore, Maryland, USA