STINNER Victor <vstin...@python.org> added the comment:
> valgrind reports leaks for test_zipimport It's not strictly a memory leak: running the same code multiple time doesn't leak memory. It's just that Python allocates memory once and never releases it (doesn't releast it at exit). --- leak4.py: Updated and simplified script. If the code is run 10 times, it doesn't leak. With 1, 10 or 100 loops (LOOPS=100), Python still says the same at exit: $ ./python -I -X showrefcount leak4.py [1574 refs, 664 blocks] Using cannot_deallocate2.patch of bpo-46417, I can see that multiple static types are not cleared at Python exit: --- Cannot deallocate type 'Exception': it still has subclasses * error Cannot deallocate type 'BaseException': it still has subclasses * Exception Cannot deallocate type 'dict': it still has subclasses * collections.defaultdict Cannot deallocate type 'object': it still has subclasses * dict * BaseException * itertools.accumulate * itertools.combinations * itertools.combinations_with_replacement * itertools.cycle * itertools.dropwhile * itertools.takewhile * itertools.islice * itertools.starmap * itertools.chain * itertools.compress * itertools.filterfalse * itertools.count * itertools.zip_longest * itertools.pairwise * itertools.permutations * itertools.product * itertools.repeat * itertools.groupby * itertools._grouper * itertools._tee * itertools._tee_dataobject * collections.deque * _collections._deque_iterator * _collections._deque_reverse_iterator * _collections._tuplegetter * _struct.Struct * _struct.unpack_iterator --- The _collections, itertools and _struct extensions implement types as static types which are not cleared at Python exit. It explains why Python says that there are still 664 memory blocks allocated at Python exit (664 blocks). I consider that this issue is a duplicate of bpo-40077. ---------- resolution: -> duplicate stage: -> resolved status: open -> closed superseder: -> Convert static types to heap types: use PyType_FromSpec() Added file: https://bugs.python.org/file50594/leak4.py _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue23769> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com