Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PySide2 memory leak during canvas paintEvent #12089

Closed
simon-kraeusel opened this issue Sep 11, 2018 · 4 comments · Fixed by #12092
Closed

PySide2 memory leak during canvas paintEvent #12089

simon-kraeusel opened this issue Sep 11, 2018 · 4 comments · Fixed by #12092
Labels
Milestone

Comments

@simon-kraeusel
Copy link
Contributor

Bug report

A memory leak occurs during every frame draw when PySide2 is used with Python3. This issue was already fixed for PySide in the method matplotlib.backends.backend_qt5agg.FigureCanvasQtAgg.paintEvent
However, an additional check for QT_API == 'PySide2' is needed.

Code for reproduction

import matplotlib
matplotlib.use('Qt5Agg')
import matplotlib.pyplot as plt
plt.plot([1,2],[1,2])
plt.show()

Actual outcome

When a redraw of the figurecanvas is forced, the program memory increases steadily. For example during resizing the popup window.

Expected outcome

Constant memory during ui execution.

Matplotlib version

  • Operating system: Windows 10
  • Matplotlib version: 2.2.2
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: 3.7

all packages are pip installed

@simon-kraeusel
Copy link
Contributor Author

The fix to this issue is:

if QT_API in ('PySide', 'PySide2') and six.PY3:
    ctypes.c_long.from_address(id(buf)).value = 1

to be inserted into
matplotlib.backends.backend_qt5agg.FigureCanvasQtAgg.paintEvent

I am new to github so don't know how to create a branch/commit/pull request sensibly. I will look into it and try to commit this fix.

@anntzer
Copy link
Contributor

anntzer commented Sep 11, 2018

Indeed looks like PySide2 also suffers from the same issue (https://bugreports.qt.io/browse/PYSIDE-140?focusedCommentId=403528&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-403528), so I agree with the fix.

@dabana
Copy link
Contributor

dabana commented Sep 11, 2018

@simon-kraeusel checkout the matplotlib developper guide for a step by step guide how to contribute.

@simon-kraeusel
Copy link
Contributor Author

@dabana Thank you. I sort of managed to get the fix into a merge request. However, I will have a closer look at the developer-guide in order to do it properly next time. Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants