-
Notifications
You must be signed in to change notification settings - Fork 55
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
Fix image memory issues #1109
Fix image memory issues #1109
Conversation
This hopefully fixes #1108.
How is the |
For arrays we stash a reference to (a shuffled copy) of the array here: pyface/pyface/ui/qt4/util/image_helpers.py Line 169 in 8adf2a1
For a PIL Line 34 in 8adf2a1
Edit: plus it looks like PIL is also stashing a reference. |
@@ -45,7 +45,9 @@ def image_to_bitmap(image): | |||
bitmap : QPixmap | |||
The corresponding QPixmap. | |||
""" | |||
return QPixmap.fromImage(image) | |||
bitmap = QPixmap.fromImage(image) | |||
bitmap._image = image |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest adding a comment explaining why this is necessary.
If this code is only consuming I'm speculating a little, so don't take this too seriously. I'm 👍 on the proposed solution but only wonder if perhaps the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but a comment explaining why this code is doing what it's doing would be useful.
There's no way I know of to create a There is a question of whether the |
Done. |
Fixes #1108 (hopefully).
This stashes a back-reference to a
QImage
when it is used to create aQPixmap
to ensure that theQImage
isn't gc-d until we're done with it.The example from TraitsUI looks like this after the fix:
Unfortunately I don't see a way to create a regression test.
For a reviewer - to replicate set up a Windows/Python3.6/Pyside2 environment with the main branch of TraitsUI and the main branch of Pyface - you should see corruption or get a segfault. Switching to this branch should fix the problem.