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.

Title: slice() leaks memory when part of a cycle
Type: resource usage Stage: resolved
Components: Interpreter Core Versions: Python 3.6, Python 3.5, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Demur Rumed, Kevin Modzelewski, benjamin.peterson, georg.brandl, pitrou, python-dev, vstinner, yselivanov
Priority: normal Keywords:

Created on 2016-03-28 20:07 by Kevin Modzelewski, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg262582 - (view) Author: Kevin Modzelewski (Kevin Modzelewski) Date: 2016-03-28 20:07
The slice type doesn't participate in GC, which means that if you happen to create a cycle involving a slice, that cycle will never get freed.  Here's an example:

def f():
    l = []
# Will consume memory without bound:
while True:

This seems pretty hard to trigger accidentally, so it might not be a huge deal -- especially since it seems to have been around for a while.  (I only checked 2.7 and trunk though.)

I think this could be solved by either having the slice class participate in GC (ie add tp_traverse and tp_clear methods), or maybe doing some type-filtering during slice_new().
msg262589 - (view) Author: Philip Dubé (Demur Rumed) * Date: 2016-03-29 03:50
Implementing tp_traverse & tp_clear seems to runs into complications due to slice_cache
msg263590 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-04-16 21:54
New changeset 879da9400529 by Benjamin Peterson in branch '2.7':
add gc support to slice (closes #26659)

New changeset 9e2176d18965 by Benjamin Peterson in branch '3.5':
add gc support to slice (closes #26659)

New changeset 870fcc50f1bd by Benjamin Peterson in branch 'default':
merge 3.5 (#26659)
Date User Action Args
2022-04-11 14:58:29adminsetgithub: 70846
2016-04-16 22:52:29martin.pantersetversions: + Python 3.5
2016-04-16 21:54:40python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg263590

resolution: fixed
stage: resolved
2016-03-29 22:18:46vstinnersetnosy: + vstinner
2016-03-29 08:16:06SilentGhostsetnosy: + georg.brandl, pitrou, benjamin.peterson, yselivanov
2016-03-29 03:50:32Demur Rumedsetnosy: + Demur Rumed
messages: + msg262589
2016-03-28 20:07:30Kevin Modzelewskicreate