This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: types.Union should support GC
Type: Stage: resolved
Components: Versions: Python 3.11, Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Guido.van.Rossum, gvanrossum, kj, miss-islington, pablogsal, serhiy.storchaka
Priority: release blocker Keywords: patch

Created on 2021-07-02 14:53 by kj, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 26993 closed kj, 2021-07-02 14:56
PR 27002 merged miss-islington, 2021-07-03 12:12
PR 27008 merged pablogsal, 2021-07-03 19:04
PR 27009 merged miss-islington, 2021-07-03 20:00
Messages (10)
msg396867 - (view) Author: Ken Jin (kj) * (Python committer) Date: 2021-07-02 14:53
types.Union objects can contain reference cycles, therefore causing memory leaks.

E.g.::

```
import sys, gc
from typing import TypeVar

gc.collect()
for _ in range(10):
 sys.gettotalrefcount()
 T = TypeVar('T')
 U = int | list[T]
 T.blah = U
 del T
 del U
 gc.collect()
```
Result:
84470
0
84488
0
84504
0
84520
0
84536
0

I'm sending a small PR soon to implement GC methods to fix this.
msg396897 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-07-03 12:12
New changeset 1097384ce964dd63686b1aac706cd0fa764c2dc9 by Ken Jin in branch 'main':
bpo-44553 : Implement GC methods for types.Union (GH-26993)
https://github.com/python/cpython/commit/1097384ce964dd63686b1aac706cd0fa764c2dc9
msg396900 - (view) Author: miss-islington (miss-islington) Date: 2021-07-03 13:33
New changeset 0856134542c1067d02c9027ddbb2a61916907e92 by Miss Islington (bot) in branch '3.10':
bpo-44553 : Implement GC methods for types.Union (GH-26993)
https://github.com/python/cpython/commit/0856134542c1067d02c9027ddbb2a61916907e92
msg396901 - (view) Author: Ken Jin (kj) * (Python committer) Date: 2021-07-03 13:35
Thanks for the helpful review and merge Serhiy.
msg396920 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-07-03 18:09
This commits seems to have broken the tracerefs buildbots:

https://buildbot.python.org/all/#/builders/484/builds/322
https://buildbot.python.org/all/#/builders/678/builds/127

Please, take a look at soon as possible, otherwise per the buildbot policy we will need to revert the commits to avoid masking other issues.
msg396921 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-07-03 20:00
New changeset bc3961485639cc73de7c4c7eed1b56f3c74939bf by Pablo Galindo in branch 'main':
bpo-44553: Correct failure in tp_new for the union object (GH-27008)
https://github.com/python/cpython/commit/bc3961485639cc73de7c4c7eed1b56f3c74939bf
msg396924 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-07-03 20:51
New changeset 000b9e803a7ec067da0a43f9a3fec16f1078215a by Miss Islington (bot) in branch '3.10':
bpo-44553: Correct failure in tp_new for the union object (GH-27008) (GH-27009)
https://github.com/python/cpython/commit/000b9e803a7ec067da0a43f9a3fec16f1078215a
msg396925 - (view) Author: Guido van Rossum (Guido.van.Rossum) Date: 2021-07-03 21:44
Thanks for the fix, Pablo!

Ken Jin, we learned something today!
msg396931 - (view) Author: Ken Jin (kj) * (Python committer) Date: 2021-07-03 22:10
Woops, thanks for the quick fix Pablo. I'm guessing the takeaway here is
that we should start tracking a GC-ed object as early as possible?
msg396938 - (view) Author: Ken Jin (kj) * (Python committer) Date: 2021-07-04 05:44
Oh I didn't see Pablo's message on the PR:

> @Fidget-Spinner For next occasions, the problem with this is that PyObject_GC_Del cannot be called like that because it overrides a bunch of cleanups like the call to _Py_ForgetReference and other possible handling.

Thanks for the explanation!
History
Date User Action Args
2022-04-11 14:59:47adminsetgithub: 88719
2021-07-04 05:44:17kjsetmessages: + msg396938
2021-07-03 22:10:25kjsetmessages: + msg396931
2021-07-03 21:44:45Guido.van.Rossumsetnosy: + Guido.van.Rossum
messages: + msg396925
2021-07-03 20:51:17pablogsalsetmessages: + msg396924
2021-07-03 20:07:19pablogsalsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-07-03 20:00:55pablogsalsetmessages: + msg396921
2021-07-03 20:00:36miss-islingtonsetpull_requests: + pull_request25569
2021-07-03 19:04:46pablogsalsetstage: resolved -> patch review
pull_requests: + pull_request25568
2021-07-03 18:47:16pablogsalsetpriority: normal -> release blocker
2021-07-03 18:09:33pablogsalsetstatus: closed -> open

nosy: + pablogsal
messages: + msg396920

resolution: fixed -> (no value)
2021-07-03 13:35:57kjsetstatus: open -> closed
resolution: fixed
messages: + msg396901

stage: patch review -> resolved
2021-07-03 13:33:50miss-islingtonsetmessages: + msg396900
2021-07-03 12:12:27miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request25563
2021-07-03 12:12:15serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg396897
2021-07-02 14:56:41kjsetkeywords: + patch
stage: patch review
pull_requests: + pull_request25554
2021-07-02 14:53:38kjcreate