enthought/chaco — Issue #42: chaco pyside memory leak
Author: robchambers
Created: 2012-02-08 15:54:15+00:00
State: open

There seems to be a memory leak in Chaco when plots are repeatedly updated (example below).

I'm only getting the leak with the qt backend, and only with pyside (not pyqt).

I'm on windows 7 (64-bit) running EPD 7.2-2 (32-bit).
PySide: 1.1.0-2
Chaco: 4.1.0-1
Pyface: 4.1.0-1

We're doing real-time plotting w/ Chaco, and after a few hundred updates the app can easily exceed 2Gb memory usage and crash. I've tried unsuccessfully to figure out where in Chaco this is happening...

Please advise if I can be of assistance in tracking this down. Am I plotting in a non-standard way--is that why other people aren't running into this?

Cheers,
Rob

```python

import os
os.environ['QT_API'] = 'pyside' #'pyqt' # Only happens with Pyside

from traits.etsconfig.etsconfig import ETSConfig
ETSConfig.toolkit = 'qt4' # Doesn't seem to happen w/ WX backend.

import numpy as np

from traits.api import HasTraits, Instance
from traitsui.api import View, VGroup, Item
from pyface.timer.api import do_after

from enable.api import Component, ComponentEditor
from chaco.api import Plot, ArrayPlotData

PERIOD_MS = 100
DATA_LENGTH = 1000

class PlotViewer(HasTraits):
"""
Example class showing a Pyside memory leak that happens whenever
a chaco plot updates...
"""

pd = Instance(ArrayPlotData)
plot = Instance(Plot)

def __init__(self):
self.plot = Plot(self.pd)
self.plot.plot(("x", "y"), type="scatter")

do_after(PERIOD_MS, self._update_pd) # Start plotting loop.

def _pd_default(self):
# A random line
pd = ArrayPlotData(x = np.arange(DATA_LENGTH),
y = np.random.rand(DATA_LENGTH))
return pd

def _update_pd(self):
''' Change the 'y' data, triggering a plot update, every PERIOD_MS ms. '''
self.pd.set_data('y', np.random.rand(DATA_LENGTH))

do_after(PERIOD_MS, self._update_pd) # Continue plotting loop...

# View #####################################################################
traits_view=View(
VGroup(
Item('plot',editor=ComponentEditor()),
show_labels=False
),
width=500, height=500
)

if __name__ == "__main__":
pv = PlotViewer()
pv.configure_traits()

```