Skip to content

plotWidget Memory Leak, pyqtgraph 0.12.4, PySide2 5.15.02 #2348

@csmotion

Description

@csmotion

Short description

I've run into a memory leak in plotWidget using pyqtgraph 0.12.4, and PySide2 5.15.02. UpdateIntensity method clears and then plots on the plotWidget. Plots display correctly, but see constant memory growth. Confirmed disappears if I disable UpdateIntensity method.

Code to reproduce

from PySide2.QtCore import Qt
from Qt import (QtGui, QtCompat, QtCore, QtWidgets, __binding__, __binding_version__,
                __qt_version__, __version__)

import pyqtgraph as pg

    def UpdateIntensity(self):
        # Plot pixel intensities
        self.plotWidgetPixelIntensity.clear()

        self.plotWidgetPixelIntensity.showGrid(x = True, y = True, alpha = 0.75)
        self.plotWidgetPixelIntensity.setLabel('bottom', 'Pixel Intensity (counts)')
        self.plotWidgetPixelIntensity.addLegend()

        penRed = pg.mkPen(color=(255, 0, 0), width=2.0)
        penBlue = pg.mkPen(color=(0, 0, 255), width=2.0)
        penGreen = pg.mkPen(color=(150, 0, 0), width=5.0, style=QtCore.Qt.DashLine)
        penPurple = pg.mkPen(color=(0, 0, 150), width=5.0, style=QtCore.Qt.DashLine)

        self.plotWidgetPixelIntensity.enableAutoRange(axis='y')
        self.plotWidgetPixelIntensity.setAutoVisible(y=True)

        self.plotWidgetPixelIntensity.plot(
            self.vr.grayBins,
            self.vr.grayPDF,
            pen = penRed,
            brush = (255, 0, 0, 100),
            fillLevel=0,
            name = 'PDF Gray'
        )

        self.plotWidgetPixelIntensity.plot(
            self.vr.grayBins,
            self.vr.grayCDF,
            pen = penGreen,
            name = 'CDF Gray'
        )

        self.plotWidgetPixelIntensity.plot(
            [
                self.vr.centroidTrackThreshold,
                self.vr.centroidTrackThreshold
            ],
            [0, 1],
            pen = penBlue
        )

        self.plotWidgetPixelIntensity.plot(
            self.vr.threshGrayBins,
            self.vr.threshGrayPDF,
            pen = penBlue,
            brush = (0, 0, 255, 100),
            fillLevel=0,
            name = 'PDF Thresh'
        )

        self.plotWidgetPixelIntensity.plot(
            self.vr.threshGrayBins,
            self.vr.threshGrayCDF,
            pen = penPurple,
            name = 'CDF Thresh'
        )

        # self.plotWidgetPixelIntensity.setLogMode(False, True)
        # self.plotWidgetPixelIntensity.setRange(xRange=[0, 255], yRange=[-3, 0])
        self.plotWidgetPixelIntensity.setRange(xRange=[0, 255], yRange=[0, 1])

Expected behavior

I get to keep my memory :)

Real behavior

plotWidget eats my memory :(

Tested environment(s)

  • PyQtGraph version: 0.12.4
  • Qt Python binding: PySide2 5.15.2 Qt 5.15.2
  • Python version: 3.7.9
  • NumPy version: 1.21.6
  • Operating system: Win 10
  • Installation method: pip

Additional context

Also using Qt.py, and QtCompat.loadUi if that's meaningful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions