Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chaco pyside memory leak #42

Closed
robchambers opened this issue Feb 8, 2012 · 3 comments
Closed

chaco pyside memory leak #42

robchambers opened this issue Feb 8, 2012 · 3 comments

Comments

@robchambers
Copy link

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

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()
@robchambers
Copy link
Author

I'd be happy to help try to fix this, but I'm not sure where to look... I imagine that switching from pyqt->pyside introduced an error that's being silently caught somewhere? Or, perhaps the error is in Pyside?

@deepankarsharma
Copy link

enthought/enable#42 fixes this issue. Once it is merged you can checkout and use enable. Alternatively if it is urgent you might want to apply the patch yourself to your local version.

@robchambers
Copy link
Author

That did it - thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants