super not working in __del__ ?

Jeff Shannon jeff at ccvcorp.com
Wed Feb 16 12:48:11 EST 2005


Christopher J. Bottaro wrote:

> 2 Questions...
> 1)  Why does this never happen in C++?  Or does it, its just never happened
> to me?
> 2)  I can understand random destruction of instantiated objects, but I find
> it weird that class definitions (sorry, bad terminology) are destroyed at
> the same time.  So __del__ can't safely instantiate any classes if its
> being called as a result of interpreter shutdown?  Boo...

Keep in mind that in Python, everything is a (dynamically created) 
object, including class objects.  My recall of C/C++ memory 
organization is pretty weak, but IIRC it gives completely different 
behavior to code, stack objects, and heap objects.  Code never needs 
to be cleaned up.  In Python, everything (including functions and 
classes) is effectively a heap object, and thus functions and classes 
can (and indeed must) be cleaned up.  Refcounting means that they 
won't ever (normally) be cleaned up while they're still in use, but 
during program shutdown refcounting necessarily ceases to apply.

The closest that would happen in C++, I believe, would manifest itself 
as memory leaks and/or access of already-freed memory.

Jeff Shannon
Technician/Programmer
Credit International




More information about the Python-list mailing list