8000 Work around a huge memory leak in PySide on Python 3 by cgohlke · Pull Request #1323 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Work around a huge memory leak in PySide on Python 3 #1323

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

Merged
merged 2 commits into from
Oct 18, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/matplotlib/backends/backend_qt4agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from __future__ import division, print_function

import os, sys
import ctypes

import matplotlib
from matplotlib.figure import Figure
Expand All @@ -15,6 +16,10 @@

DEBUG = False

_decref = ctypes.pythonapi.Py_DecRef
_decref.argtypes = [ctypes.py_object]
_decref.restype = None


def new_figure_manager( num, *args, **kwargs ):
"""
Expand Down Expand Up @@ -95,6 +100,8 @@ def paintEvent( self, e ):
else:
stringBuffer = self.renderer._renderer.tostring_argb()

refcnt = sys.getrefcount(stringBuffer)

qImage = QtGui.QImage(stringBuffer, self.renderer.width,
self.renderer.height,
QtGui.QImage.Format_ARGB32)
Expand All @@ -106,6 +113,14 @@ def paintEvent( self, e ):
p.setPen( QtGui.QPen( QtCore.Qt.black, 1, QtCore.Qt.DotLine ) )
p.drawRect( self.rect[0], self.rect[1], self.rect[2], self.rect[3] )
p.end()

# This works around a bug in PySide 1.1.2 on Python 3.x,
# where the reference count of stringBuffer is incremented
# but never decremented by QImage.
# TODO: revert PR #1323 once the issue is fixed in PySide.
del qImage
if refcnt != sys.getrefcount(stringBuffer):
_decref(stringBuffer)
else:
bbox = self.blitbox
l, b, r, t = bbox.extents
Expand Down
0