Skip to content

Commit

Permalink
Work around PyQt memory leak on the Krita::documents() method.
Browse files Browse the repository at this point in the history
  • Loading branch information
FeepingCreature committed Nov 4, 2024
1 parent a83f898 commit 05b4dbf
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion ai_diffusion/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,18 @@ def current_time(self):

@property
def is_valid(self):
return self._doc in Krita.instance().documents()
# workaround 144MB/document/day pykrita memory leak (experimentally determined).
# `documents()` returns a `QList<Document*>`. The QList is cleaned up, but SIP
# doesn't know what to make of the pointers and just leaks them.
# If Krita ever fixes the documents() method, this will cause a double-delete and
# start crashing. So if you're seeing crashes on a new version, this is a good
# candidate.
# return self._doc in Krita.instance().documents()
documents = Krita.instance().documents()
result = self._doc in documents
for document in documents:
document.deleteLater()
return result

@property
def is_active(self):
Expand Down

0 comments on commit 05b4dbf

Please sign in to comment.