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.

Author vstinner
Recipients rkuska, serhiy.storchaka, vstinner
Date 2022-01-28.02:41:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1643337662.73.0.0850655108337.issue23769@roundup.psfhosted.org>
In-reply-to
Content
> 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.
History
Date User Action Args
2022-01-28 02:41:02vstinnersetrecipients: + vstinner, serhiy.storchaka, rkuska
2022-01-28 02:41:02vstinnersetmessageid: <1643337662.73.0.0850655108337.issue23769@roundup.psfhosted.org>
2022-01-28 02:41:02vstinnerlinkissue23769 messages
2022-01-28 02:41:02vstinnercreate