Memory leak when using PySide instead of PyQt
-
Hi, I am using pyqtgraph to display a simple sine wave form. Which works perfectly with PyQt4. ( using windows 7 , python 2.7 ) when we check task manager, the memory occupied by running python instant stays steady. But if i use PySide instead of PyQt, the memory taken by the python instance starts climbing up! This is my code
@
import sys#from PyQt4 import QtGui
#from PyQt4 import QtCorefrom PySide import QtGui
from PySide import QtCoreimport numpy as np
import pyqtgraph as pgclass GraphDisplay(QtGui.QMainWindow):
def __init__( self , parent =None): QtGui.QMainWindow.__init__ (self , parent) self.setGeometry( QtCore.QRect(200, 100 , 1000, 300 )) self.framelength = 400 self.flowwindow = 2 self.index =0 self.indexmax = (1000 - self.framelength) / self.flowwindow self.dataPlot = np.cos(np.linspace(0, 10*np.pi , 1000)) self.graph = pg.PlotItem() self.graph.plot( self.dataPlot) self.graph.showGrid(x=True, y=True) self.view = pg.GraphicsView() self.view.setCentralItem(self.graph) self.setCentralWidget(self.view) self.timer = QtCore.QTimer() self.timer.timeout.connect(self.UpdatePlotData) self.timer.start(200) def UpdatePlotData(self): self.index += 1 if (self.indexmax == self.index): self.index = 0 self.graph.clear() #print self.graph.plot(self.dataPlot[ self.index * self.flowwindow : self.framelength + self.index * self.flowwindow], pen=(0,255,0) , clear=True) self.graph.plot(self.dataPlot[ self.index * self.flowwindow : self.framelength + self.index * self.flowwindow], pen=(0,255,0) , clear=True)
def ShowWindow():
app = QtGui.QApplication(sys.argv)
qb = GraphDisplay()
qb.show()
sys.exit(app.exec_())if name == 'main':
ShowWindow()@
if we apply the print statement on line 44 and comment line 45 we get the console result like this
@For PyQt4
<pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem object at 0x04118F60>
<pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem object at 0x04118F60>
<pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem object at 0x04118F60>
<pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem object at 0x04118F60>
<pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem object at 0x04118F60>
<pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem object at 0x04118F60>
<pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem object at 0x04118F60>For PySide
<pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem(this = 0x3bbe560 , parent = 0x355ca50 , pos = QPointF(0, 0) , z = 0 , flags = ( ItemHasNoContents ) ) at 0x03A8D738>
<pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem(this = 0x3bbd8b8 , parent = 0x355ca50 , pos = QPointF(0, 0) , z = 0 , flags = ( ItemHasNoContents ) ) at 0x03AA9828>
<pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem(this = 0x3bbebf0 , parent = 0x355ca50 , pos = QPointF(0, 0) , z = 0 , flags = ( ItemHasNoContents ) ) at 0x03A8D738>
<pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem(this = 0x3bbd888 , parent = 0x355ca50 , pos = QPointF(0, 0) , z = 0 , flags = ( ItemHasNoContents ) ) at 0x03AA9828>
<pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem(this = 0x3bbec38 , parent = 0x355ca50 , pos = QPointF(0, 0) , z = 0 , flags = ( ItemHasNoContents ) ) at 0x03A8D738>
<pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem(this = 0x3bbc190 , parent = 0x355ca50 , pos = QPointF(0, 0) , z = 0 , flags = ( ItemHasNoContents ) ) at 0x03AA9828>
<pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem(this = 0x3bbc2c8 , parent = 0x355ca50 , pos = QPointF(0, 0) , z = 0 , flags = ( ItemHasNoContents ) ) at 0x03A8D738>
<pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem(this = 0x3bbbe48 , parent = 0x355ca50 , pos = QPointF(0, 0) , z = 0 , flags = ( ItemHasNoContents ) ) at 0x03AA9828>
<pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem(this = 0x3bbcb38 , parent = 0x355ca50 , pos = QPointF(0, 0) , z = 0 , flags = ( ItemHasNoContents ) ) at 0x03A8D738>
<pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem(this = 0x3bbe068 , parent = 0x355ca50 , pos = QPointF(0, 0) , z = 0 , flags = ( ItemHasNoContents ) ) at 0x03AB5E90>@The memory location at which the object is created getting changed on each iteration. Is there any way to avoid memory leak ? Please help.
-
I think this is not the problem with pyqtgraph, please see this,
"reply from pyqtgraph maintainer":https://groups.google.com/forum/?fromgroups=#!topic/pyqtgraph/3LcTnVRKcbo