Commit f3cead4
gh-116946: Implement the GC protocol for _tkinter tkapp and tktimertoken
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>1 parent 05679f3 commit f3cead4
3 files changed
Lines changed: 102 additions & 13 deletions
File tree
- Lib/test/test_tkinter
- Misc/NEWS.d/next/Library
- Modules
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
| 13 | + | |
11 | 14 | | |
12 | 15 | | |
13 | 16 | | |
| |||
350 | 353 | | |
351 | 354 | | |
352 | 355 | | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
353 | 386 | | |
354 | 387 | | |
355 | 388 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
626 | 626 | | |
627 | 627 | | |
628 | 628 | | |
629 | | - | |
| 629 | + | |
| 630 | + | |
630 | 631 | | |
631 | 632 | | |
632 | 633 | | |
| |||
2810 | 2811 | | |
2811 | 2812 | | |
2812 | 2813 | | |
2813 | | - | |
| 2814 | + | |
| 2815 | + | |
2814 | 2816 | | |
2815 | 2817 | | |
2816 | 2818 | | |
| |||
2821 | 2823 | | |
2822 | 2824 | | |
2823 | 2825 | | |
2824 | | - | |
2825 | | - | |
| 2826 | + | |
| 2827 | + | |
| 2828 | + | |
| 2829 | + | |
| 2830 | + | |
2826 | 2831 | | |
2827 | | - | |
2828 | | - | |
2829 | | - | |
| 2832 | + | |
| 2833 | + | |
| 2834 | + | |
| 2835 | + | |
2830 | 2836 | | |
2831 | | - | |
| 2837 | + | |
| 2838 | + | |
| 2839 | + | |
| 2840 | + | |
| 2841 | + | |
| 2842 | + | |
| 2843 | + | |
| 2844 | + | |
| 2845 | + | |
| 2846 | + | |
2832 | 2847 | | |
2833 | | - | |
| 2848 | + | |
| 2849 | + | |
| 2850 | + | |
| 2851 | + | |
| 2852 | + | |
| 2853 | + | |
| 2854 | + | |
| 2855 | + | |
| 2856 | + | |
| 2857 | + | |
| 2858 | + | |
| 2859 | + | |
| 2860 | + | |
2834 | 2861 | | |
2835 | 2862 | | |
2836 | 2863 | | |
| |||
3124 | 3151 | | |
3125 | 3152 | | |
3126 | 3153 | | |
| 3154 | + | |
| 3155 | + | |
| 3156 | + | |
| 3157 | + | |
| 3158 | + | |
| 3159 | + | |
| 3160 | + | |
| 3161 | + | |
| 3162 | + | |
| 3163 | + | |
| 3164 | + | |
| 3165 | + | |
| 3166 | + | |
| 3167 | + | |
| 3168 | + | |
| 3169 | + | |
| 3170 | + | |
| 3171 | + | |
| 3172 | + | |
3127 | 3173 | | |
3128 | 3174 | | |
3129 | 3175 | | |
3130 | | - | |
3131 | | - | |
| 3176 | + | |
| 3177 | + | |
| 3178 | + | |
3132 | 3179 | | |
3133 | 3180 | | |
3134 | 3181 | | |
3135 | 3182 | | |
3136 | | - | |
3137 | | - | |
| 3183 | + | |
| 3184 | + | |
3138 | 3185 | | |
3139 | 3186 | | |
3140 | 3187 | | |
| |||
3341 | 3388 | | |
3342 | 3389 | | |
3343 | 3390 | | |
| 3391 | + | |
| 3392 | + | |
3344 | 3393 | | |
3345 | 3394 | | |
3346 | 3395 | | |
| |||
3353 | 3402 | | |
3354 | 3403 | | |
3355 | 3404 | | |
| 3405 | + | |
3356 | 3406 | | |
3357 | 3407 | | |
3358 | 3408 | | |
| |||
3400 | 3450 | | |
3401 | 3451 | | |
3402 | 3452 | | |
| 3453 | + | |
| 3454 | + | |
3403 | 3455 | | |
3404 | 3456 | | |
3405 | 3457 | | |
| |||
3412 | 3464 | | |
3413 | 3465 | | |
3414 | 3466 | | |
| 3467 | + | |
3415 | 3468 | | |
3416 | 3469 | | |
3417 | 3470 | | |
| |||
0 commit comments