Use new_from_bytes instead of new_from_data, to avoid memory leaks by cgkoutzigiannis · Pull Request #4814 · beeware/toga · GitHub
Skip to content

Use new_from_bytes instead of new_from_data, to avoid memory leaks - #4814

Merged
freakboy3742 merged 1 commit into
beeware:mainfrom
cgkoutzigiannis:fix-4684
Oct 26, 2026
Merged

freakboy3742 merged 1 commit into
beeware:mainfrom
cgkoutzigiannis:fix-4684

Conversation

@cgkoutzigiannis

Copy link
Copy Markdown
Contributor

Fixes #4684.

Changed the Image GTK implementation to use new_from_bytes, instead of new_from_data, to avoid memory leaks.

Based on the GTK docs for new_from_data, it expects a destroy parameter, that is called to free the data allocated. So passing None, doesn't free any memory.
On the other hand, new_from_bytes doesn't take a parameter like that and frees memory on it's own.

There is an ongoing discussion about this issue, since this is a bug with the Python bindings.

PR Checklist:

  • I will abide by the BeeWare Code of Conduct
  • I have read and have followed the CONTRIBUTING.md file
  • This PR was generated or assisted using an AI tool

@cgkoutzigiannis
cgkoutzigiannis marked this pull request as ready for review October 19, 2026 20:16
@kattni

kattni commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

@freakboy3742 freakboy3742 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks for the PR!

@freakboy3742
freakboy3742 merged commit 08e0336 into beeware:main Oct 26, 2026
62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GTK Image Memory Leak

3 participants