Skip to content

QMenus not destroyed (memory leak) #2497

@bbc131

Description

@bbc131

I found, that when you repeatedly instantiate PlotItems and delete them again, the corresponding QMenu objects for the context menus of the plots never get destroyed. I saw lot's of QMenu instances using GammaRay (https://www.kdab.com/development-resources/qt-tools/gammaray/)

But this can simply be reproduced with the following snippet. The more often you create, add and remove new plot instances the more memory is used. Simply increase N to e.g. 100, 500, 1000, 2000 and check the memory usage.

import pyqtgraph as pg

app = pg.mkQApp()
widget = pg.GraphicsLayoutWidget()
widget.show()

N = 10
for i in range(N):
    plot = pg.PlotItem()
    plot.plot(x=[0,i, N], y=[0.0, 1.0, 0.0])
    widget.addItem(plot)
    app.processEvents()
    widget.removeItem(plot)

if __name__ == '__main__':
    pg.exec()

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