]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-116946: Implement the GC protocol for _tkinter tkapp and tktimertoken (GH-152310)
authorSerhiy Storchaka <storchaka@gmail.com>
Fri, 10 Jul 2026 16:44:44 +0000 (19:44 +0300)
committerGitHub <noreply@github.com>
Fri, 10 Jul 2026 16:44:44 +0000 (19:44 +0300)
commit6d5908368dc7936802d62413344dd4596abc4159
treedd874b47a71f5fb879a64fa7c99fa2105a3f272c
parentc59c95f7b42844266d635e6ae60cae0091d64b56
gh-116946: Implement the GC protocol for _tkinter tkapp and tktimertoken (GH-152310)

The _tkinter.tkapp and _tkinter.tktimertoken types never implemented the
garbage collector protocol, so reference cycles through an interpreter's
trace function or a timer handler's callback could not be collected.

A pending timer is kept alive by the Tcl event loop, which fires it even
after the Python token is dropped, so it is treated as a GC root (only its
callback is traversed) and collecting it never cancels a live timer.  The
GC slots use a plain cast rather than the type-checking macro, since the
collector may visit a surviving object at shutdown after module clearing
has reset the global type pointers.  Deallocation cancels any pending timer
so its callback cannot run on freed memory.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Lib/test/test_tkinter/test_misc.py
Misc/NEWS.d/next/Library/2026-06-26-14-05-00.gh-issue-116946.Kp7raZ.rst [new file with mode: 0644]
Modules/_tkinter.c