[ python-Bugs-1048495 ] Memory leaks?

SourceForge.net noreply at sourceforge.net
Sun Oct 17 02:04:58 CEST 2004


Bugs item #1048495, was opened at 2004-10-16 18:49
Message generated for change (Comment added) made by tim_one
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1048495&group_id=5470

Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Roman Mamedov (romanrm)
Assigned to: Nobody/Anonymous (nobody)
Summary: Memory leaks?

Initial Comment:
Open python command-line interpreter. Enter:

>>> a = range (10000000)

Observe Python memory usage. 20 Mb real, 159 Mb virtual memory here(I'm on windows). Enter:

>>> a = 0

Observe memory usage again. 120 mb real/120 mb virtual. OK, this is a garbage collected language, lets try to garbage-collect.

>>> import gc
>>> gc.collect()
0

That didn't help. The memory usage is still at 120/120.

So, the question is, when that "range" object will get deleted, or how to do delete it manually? Why garbage collection doesn't get rid of "orphaned" objects?

Any comments?

----------------------------------------------------------------------

>Comment By: Tim Peters (tim_one)
Date: 2004-10-16 20:04

Message:
Logged In: YES 
user_id=31435

range() constructs a list.  The list takes 4 bytes/entry, so 
you get about 40MB reclaimed when the list goes away.  The 
space for integer objects happens to be immortal, though, 
and the approximately 12 bytes per integer doesn't go away.  
Space for floats is also immortal, BTW.

There aren't easy resolutions.  For example, the caching of 
space for integer objects in a dedicated internal int freelist 
speeds many programs.  And if Python didn't do special 
memory allocation for ints, malloc overhead would probably 
boost the memory burden in your example to 16 bytes/int.

So there are tradeoffs.  Note that xrange() can usually be 
used instead to create one integer at a time (instead of 
creating 10 million simultaneously).  Then the memory burden 
is trivial.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1048495&group_id=5470


More information about the Python-bugs-list mailing list