You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
test/test_typing.py:8101: count=1 (+1) -- class Meta(type):
test/test_typing.py:5595: count=1 (+1) -- class D(type(ClassVar[int])):
Many creation of classes. The question is why these classes still seem to be alive after the test completed.
Maybe something is delaying the deletion of these temporary classes. Maybe they are registered in caches and caches are not fully cleared "immediately" but "later".
I don't know if its helpful but test.test_typing.ProtocolTests.test_protocols_isinstance_py36 seems to leak quite consistently just after the warm-up. If you write something like:
Thanks Victor for solving this. I was a little late to the "party", but I can confirm that it solves the leak at least in every one of my setups (Linux, Windows, MacOS).
Activity
sobolevn commentedon Jun 27, 2024
It does not reproduce on macos, so it is windows-specific.
I don't have access to Windows machince, so I cannot help with this :(
vstinner commentedon Jun 27, 2024
./python -m test test_typing -R 3:3result is very random. Example of 3 runs on Linux:test_typing leaked [3, 0, 0] memory blocks, sum=3 (this is fine)test_typing leaked [2, 1, 0] memory blocks, sum=3 (this is fine)test_typing leaked [1, 0, 1] memory blocks, sum=2 (this is fine)vstinner commentedon Jun 27, 2024
Even if I run more iterations, I only see a total of sum=3. "Leaks" are only in the first 5 runs (after the 3 warmups):
./python -m test test_typing -R 3:20:test_typing leaked [2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] memory blocks, sum=3 (this is fine)test_typing leaked [0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] memory blocks, sum=3 (this is fine)test_typing leaked [1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] memory blocks, sum=3 (this is fine)vstinner commentedon Jun 27, 2024
I tried tracemalloc:
Script:
Run tests:
./python -X tracemalloc -m test test_typing -R 3:3.Example of script output:
Only growing counts are interesting:
class Old(Generic[*Ts]): ...nm_tpl.__bases__ = basesenum_class = super().__new__(metacls, cls, bases, classdict, **kwds)class Meta(type):class D(type(ClassVar[int])):Many creation of classes. The question is why these classes still seem to be alive after the test completed.
Maybe something is delaying the deletion of these temporary classes. Maybe they are registered in caches and caches are not fully cleared "immediately" but "later".
JelleZijlstra commentedon Jun 27, 2024
I recall @encukou telling me it had something to do with materialization of
__dict__.AlexWaygood commentedon Jun 27, 2024
see #115822
encukou commentedon Jun 27, 2024
This is a different pattern than the one related to dict rematerialization (#115822)
picnixz commentedon Jun 27, 2024
I don't know if its helpful but
test.test_typing.ProtocolTests.test_protocols_isinstance_py36seems to leak quite consistently just after the warm-up. If you write something like:You'll see patterns of the form
(The test invokes
isinstance(X, Y)withYaProtocolclass).In addition, we seem to have some pattern:
Either it is
or it is
(either you have a 2 at position 4 and nothing afterwards or a 1 at 4 and a 1 at 9).
vstinner commentedon Jun 27, 2024
GenericAlias and Union have no clear() function, but it doesn't seem to make any difference to add them:
vstinner commentedon Jun 27, 2024
test_functools has a similar issue: #120163
23 remaining items
pythongh-121084: Call _abc_registry_clear() when checking refleaks (p…
pythongh-121084: Clear typing ABC caches when checking for refleaks
pythongh-121084: Fix test_typing random leaks
gh-121084: Fix test_typing random leaks (#121360)
pythongh-121084: Fix test_typing random leaks (pythonGH-121360)
pythongh-121084: Fix test_typing random leaks (pythonGH-121360)
vstinner commentedon Jul 4, 2024
test_typing was fixed by 5f660e8.
[3.12] gh-121084: Fix test_typing random leaks (GH-121360) (#121372)
[3.13] gh-121084: Fix test_typing random leaks (GH-121360) (#121373)
Eclips4 commentedon Jul 4, 2024
Thanks Victor for solving this. I was a little late to the "party", but I can confirm that it solves the leak at least in every one of my setups (Linux, Windows, MacOS).
pythongh-121084: Call _abc_registry_clear() when checking refleaks (p…
pythongh-121084: Fix test_typing random leaks (python#121360)
pythongh-121084: Call _abc_registry_clear() when checking refleaks (p…
pythongh-121084: Fix test_typing random leaks (python#121360)