Bugs item #1525678, was opened at 2006-07-20 03:57
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1525678&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Connelly (connelly)
Assigned to: Nobody/Anonymous (nobody)
Summary: exec and eval allocate lots of memory and do not free it

Initial Comment:
I'm not sure if this is a bug.  The "bug" is that if I start a new Python 
session, create a dict or list called d which takes around 2 MB of 
memory, and then I set d = eval(repr(d)), the Python process now is 
using ~38 MB of memory more than where it started at.  The high 
memory usage continues even after d is deleted.

Example 1:

% python
>>> # Memory use: 3216 KB
>>> d = dict.fromkeys(range(50000))
>>> # Memory use: 5400 KB
>>> d = eval('%r' % d)
>>> # Memory use: 41620 KB
>>> del d
>>> # Memory use: 40080 KB

I am using Python 2.4.1 (#65, Mar 30 2005) on Windows XP SP2 with 
512 MB RAM.

If we start with a larger initial dict -- say 
dict.fromkeys(range(1000**2)), then the line d = eval('%r' % d) can 
easily cause the process to start paging to disk, even though both the 
data structure and its string representation fit easily in memory.

Perhaps this behavior is due Python caching bytecodes.  One 
peculiarity about this "bug" is that if Example 1 is repeated with a 
second variable such as "d2", which is set to the value 
dict.fromkeys(range(50000,100000)), then the memory usage ends up 
exactly at 40080 KB after the second "del" statement.  If Python were 
caching the bytecodes, then one would expect the repetition of the 
example to put the memory usage at ~80000 KB.


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

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1525678&group_id=5470
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to