https://github.com/python/cpython/commit/b4067cd6e88f579e842e2b977d5bcbda69ba830c
commit: b4067cd6e88f579e842e2b977d5bcbda69ba830c
branch: main
author: Serhiy Storchaka <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-09-18T21:03:47+03:00
summary:

gh-69365: Fix reference leak in IDLE search dialogs (GH-157754)

Remove the variable trace that clears the error label when the label
is destroyed, so that it does not keep the dialog alive.

files:
M Lib/idlelib/searchbase.py

diff --git a/Lib/idlelib/searchbase.py b/Lib/idlelib/searchbase.py
index da96a047348094..9bb247a6c178c8 100644
--- a/Lib/idlelib/searchbase.py
+++ b/Lib/idlelib/searchbase.py
@@ -139,7 +139,11 @@ def create_error_label(self):
         self.error_label = Label(self.frame, text=' ', foreground='red')
         self.error_label.grid(row=self.row, column=1, sticky="nw")
         self.row = self.row + 1
-        self.engine.patvar.trace_add('write', lambda *args: 
self.show_error(''))
+        patvar = self.engine.patvar
+        trace = patvar.trace_add('write', lambda *args: self.show_error(''))
+        # The trace holds the dialog, remove it with the label.
+        self.error_label.bind('<Destroy>',
+                              lambda e: patvar.trace_remove('write', trace))
 
     def make_frame(self,labeltext=None):
         '''Return (frame, label).

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to