-
-
Notifications
You must be signed in to change notification settings - Fork 674
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 memory leak for toga.Icon and toga.Image on Cocoa #2472
Conversation
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.
Can you give any explanation for the discrepancy in approaches between the two? Both makes sense; but it's not clear to me why there's a disparity. The Image
approach is using the _needs_release
language of Rubicon; but it's being used on a Toga object, so unless I'm missing something, it's really doing the same thing as self.native is None
(just more explicitly), but then Icon isn't using the same explicit approach. The biggest change is the drop of the native.retain()
in icon... which I swear was needed at some point, but you've got a clean pass on CI, which was a reliable way to reproduce the problem.
Am I missing something here?
Its black magic :) Jokes aside, let me try to explain my choices (and please do question them!).
|
Ah - the consequences of the
It's an internal optimisation. Some APIs (e.g., screenshot and camera APIs) return NSImage objects; without a It's not a documented API (at least, not currently) because we don't want to encourage the use of that mechanism; but it's an easy performance win for internal purposes. IIRC, it's not a huge performance issue on macOS; but on Windows, the conversion process is quite slow, so it makes a big difference.
The use case that was failing was having 2 |
Fixes #2468 by explicitly releasing any successfully create NSImage on del.
PR Checklist: