From b3a579fd004f9a841038b6adf6d4ec14dbe8748a Mon Sep 17 00:00:00 2001 From: Ales Erjavec Date: Thu, 29 Mar 2018 12:03:57 +0200 Subject: [PATCH] ScatterPlotItem: Fix a GC memory leak due to numpy issue 6581 --- pyqtgraph/graphicsItems/ScatterPlotItem.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pyqtgraph/graphicsItems/ScatterPlotItem.py b/pyqtgraph/graphicsItems/ScatterPlotItem.py index 443cc220..30e6cf89 100644 --- a/pyqtgraph/graphicsItems/ScatterPlotItem.py +++ b/pyqtgraph/graphicsItems/ScatterPlotItem.py @@ -857,11 +857,18 @@ class SpotItem(object): def __init__(self, data, plot): #GraphicsItem.__init__(self, register=False) self._data = data - self._plot = plot + # SpotItems are kept in plot.data["items"] numpy object array which + # does not support cyclic garbage collection (numpy issue 6581). + # Keeping a strong ref to plot here would leak the cycle + self.__plot_ref = weakref.ref(plot) #self.setParentItem(plot) #self.setPos(QtCore.QPointF(data['x'], data['y'])) #self.updateItem() + @property + def _plot(self): + return self.__plot_ref() + def data(self): """Return the user data associated with this spot.""" return self._data['data']