reference counter and __del__

Martin von Loewis loewis at informatik.hu-berlin.de
Tue Jul 11 08:50:52 EDT 2000


Thomas Thiele <thiele at muc.das-werk.de> writes:

> 1. I have the problem that not all of my objects are destroyed and I
> don't know where and why, so I wonder if there a way to check out from
> where and how many references to a special object exists? 

Use sys.getrefcount, or the garbage collector included in the current
development version of Python (which may become Python 2 later this
year).

> 2. When __del__ is called the object will be detroyed, correct?

Vice versa. When the object is going to be destroyed, then __del__ is
invoked. Actually, when __del__ brings the object back into life, it
will not be destroyed.

> 3. Why is __init__ not called when I unpickle an object? 

a) __init__ is called when unpickling, provided __getinitargs__ is
   defined.
b) Since 1.5.x (for some x), __init__ is not normally called, because
   getting the init args right without __getinitargs__ is tricky. 
   Essentially, pickled objects were required to accept 0 arguments
   to __init__, which is often undesirable.

Regards,
Martin



More information about the Python-list mailing list