[issue26659] slice() leaks memory when part of a cycle

Kevin Modzelewski report at bugs.python.org
Mon Mar 28 16:07:30 EDT 2016


New submission from Kevin Modzelewski:

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 = []
    l.append(slice(l))
# Will consume memory without bound:
while True:
    f()

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().

----------
components: Interpreter Core
messages: 262582
nosy: Kevin Modzelewski
priority: normal
severity: normal
status: open
title: slice() leaks memory when part of a cycle
type: resource usage
versions: Python 2.7, Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26659>
_______________________________________


More information about the Python-bugs-list mailing list