[ python-Bugs-1469629 ] __dict__ = self in subclass of dict causes a memory leak?
SourceForge.net
noreply at sourceforge.net
Thu Apr 13 07:04:48 CEST 2006
Bugs item #1469629, was opened at 2006-04-13 05:04
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=1469629&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: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Dobes V (dobesv)
Assigned to: Nobody/Anonymous (nobody)
Summary: __dict__ = self in subclass of dict causes a memory leak?
Initial Comment:
Using:
ActivePython 2.4.2 Build 10 (ActiveState Corp.) based
on
Python 2.4.2 (#67, Jan 17 2006, 15:36:03) [MSC v.1310
32 bit (Intel)] on win32
For reasons I do not understand, the following class
leaks itself continuously:
class AttrDict(dict):
def __init__(self, *args, **kw):
dict.__init__(self, *args, **kw)
self.__dict__ = self
Whereas this version does not:
class AttrDict(dict):
def __init__(self, *args, **kw):
dict.__init__(self, *args, **kw)
def __getattr__(self, key):
return self[key]
def __setattr__(self, key, value):
self[key] = value
My test looks like this:
for n in xrange(1000000):
import gc
gc.collect()
ad = AttrDict()
ad['x'] = n
ad.y = ad.x
print n, ad.x, ad.y
And I sit and watch in the windows task manager while
the process grows and grows. With the __getattr__
version, it doesn't grow.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1469629&group_id=5470
More information about the Python-bugs-list
mailing list