Memory leak while looping

Roger Hancock roger_hancock at
Thu Apr 17 07:00:01 CEST 2003

I'm just starting to play with writing C extensions for Python.  In
the process of doing so, I called one of my extension functions
thousands of times only to discover that a leak was eating up all the
memory in my system.  Upon further investigation, I found I could
produce the same result with the following python code with my
extension completely out of the picture:

#!/usr/bin/env python2

for i in range(1,10000000):
    item = i

I would have thought that the memory for "item" would be freed as new
"item"s were created.  However, this doesn't seem to be the case.  I
would appreciate any clarification on this issue.



More information about the Python-list mailing list