From 787d521f52ea8316668bcc2653f986dfda3d5228 Mon Sep 17 00:00:00 2001 From: Antti Soininen Date: Wed, 16 Oct 2024 12:47:26 +0300 Subject: [PATCH] Plug memory leak Better setting document in editor to None instead of instantiating a QTextDocument without parent. --- spinetoolbox/widgets/code_text_edit.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spinetoolbox/widgets/code_text_edit.py b/spinetoolbox/widgets/code_text_edit.py index cc115f7db..f8524d7e8 100644 --- a/spinetoolbox/widgets/code_text_edit.py +++ b/spinetoolbox/widgets/code_text_edit.py @@ -65,10 +65,11 @@ def setPlainText(self, text): self.setDocument(doc) def setDocument(self, doc): - doc.setDocumentLayout(QPlainTextDocumentLayout(doc)) + if doc is not None: + doc.setDocumentLayout(QPlainTextDocumentLayout(doc)) + doc.setDefaultFont(self.font()) super().setDocument(doc) self._highlighter.setDocument(doc) - doc.setDefaultFont(self.font()) self.setTabStopDistance(QFontMetrics(self.font()).horizontalAdvance(4 * " ")) def line_number_area_width(self):