garbage collection - Python __del__ method for classes? -
i'm interested in adding hooks code when class (as opposed instance) garbage collected or otherwise falls out of memory. here example code:
def make_objects(): class a(type): def __del__(cls): print 'class deleted' class b(object): __metaclass__ = def __del__(self): print 'instance deleted' b = b() print 'making objects' make_objects() print 'finished'
i hoping see:
- making objects
- instance deleted
- class deleted
- finished
but instead saw was:
- making objects
- instance deleted
- finished
if modify code explicitly call del b
, makes no difference:
def make_objects(): class a(type): def __del__(cls): print 'class deleted' class b(object): __metaclass__ = def __del__(self): print 'instance deleted' del b
output:
- making objects
- finished
my question is: possible hook object being deleted? there preventing class b
being deleted may not aware of?
Comments
Post a Comment