PyQtChart QLineSeries.replace(QPolygonF) generate memory leak

296 Views Asked by At

As you can see, my code is very simple, it only calls QLineSeries.replace(QPolygonF) periodically.

But when the code executes, memory the application used keeps on increasing.

import sys

from PyQt5.QtCore import QTimer
from PyQt5.QtGui  import QPolygonF
from PyQt5.QtWidgets import QApplication, QMainWindow

from PyQt5.QtChart import QChart, QChartView, QLineSeries

class DemoWindow(QMainWindow):
    def __init__(self, parent=None):
        super(DemoWindow, self).__init__(parent=parent)

        self.plotChart = QChart()
        self.plotChart.legend().hide()

        self.plotView = QChartView(self.plotChart)
        self.setCentralWidget(self.plotView)

        self.plotCurve = QLineSeries()
        self.plotChart.addSeries(self.plotCurve)

        self.plotChart.createDefaultAxes()

        self.polyline = QPolygonF(1000)

        self.tmrPlot = QTimer()
        self.tmrPlot.setInterval(100)
        self.tmrPlot.timeout.connect(self.on_tmrPlot_timeout)
        self.tmrPlot.start()

    def on_tmrPlot_timeout(self):
        self.plotCurve.replace(self.polyline)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    win = DemoWindow()
    win.show()
    sys.exit(app.exec_())
0

There are 0 best solutions below