Message28217
| Author |
dobesv |
| Recipients |
| Date |
2006年04月13日.05:04:48 |
| SpamBayes Score |
| Marked as misclassified |
| Message-id |
| In-reply-to |
| Content |
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.
|
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2007年08月23日 14:39:23 | admin | link | issue1469629 messages |
| 2007年08月23日 14:39:23 | admin | create |
|