Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. Memory leak when using PySide instead of PyQt
Forum Updated to NodeBB v4.3 + New Features

Memory leak when using PySide instead of PyQt

Scheduled Pinned Locked Moved Language Bindings
2 Posts 1 Posters 3.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    afilash
    wrote on last edited by
    #1

    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 QtCore

    from PySide import QtGui
    from PySide import QtCore

    import numpy as np
    import pyqtgraph as pg

    class 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.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      afilash
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved