If a heap type does not have Py_TPFLAGS_HAVE_GC or doesn't not implement tp_traverse, the garbage collector may fail to collect the type and most of its instances at Python exit. The problem is worse when sub-interpreters are involved: if a sub-interpreter exits and does not clear all of its memory, the other interpreters will continue running with these leaks.
See issue gh-87138 for the rationale.
I wrote an article on the lock type which had this bug and caused a memory leak: https://vstinner.github.io/subinterpreter-leaks.html
Linked PRs
The following PRs were directly closed because the types are immutable and empty:
The following PRs were wrongly merged so we reverted them:
PRs for reverting the above commits:
If a heap type does not have Py_TPFLAGS_HAVE_GC or doesn't not implement tp_traverse, the garbage collector may fail to collect the type and most of its instances at Python exit. The problem is worse when sub-interpreters are involved: if a sub-interpreter exits and does not clear all of its memory, the other interpreters will continue running with these leaks.
See issue gh-87138 for the rationale.
I wrote an article on the lock type which had this bug and caused a memory leak: https://vstinner.github.io/subinterpreter-leaks.html
Linked PRs
zlibobjects #138290zlibobjects (GH-138290) #138327zlibobjects (GH-138290) #138328_tkinter.Tk{app,tt}Object#138331_curses_panel.panel#138333_curses_panel.panel(GH-138333) #138427_curses_panel.panel(GH-138333) #138428_functools._lru_list_elem#138334Py_TPFLAGS_IMMUTABLETYPEtoselect.[e]poll#138340Py_TPFLAGS_IMMUTABLETYPEto_random.Random#138341Py_TPFLAGS_IMMUTABLETYPEto several internal types #138582_tkinter.Tk{app,tt}Object(#138331)" #138807_thread.lockand_thread.RLock#141268_thread.lockand_thread.RLock#141448The following PRs were directly closed because the types are immutable and empty:
_thread._localdummy#138329_tokenize.TokenizerIter#138330_ssl.Certificate#138332The following PRs were wrongly merged so we reverted them:
bz2objects #138266bz2objects (GH-138266) #138320bz2objects (GH-138266) #138322lzmaobjects #138288lzmaobjects (GH-138288) #138321lzmaobjects (GH-138288) #138323_hashlibobjects #138289_hashlibobjects (GH-138289) #138324_hashlibobjects (GH-138289) #138326PRs for reverting the above commits: