__del__: when to use it? What happens when you SystemExit/NameError wrt del? Method vs function calls.
Veek. M
vek.m1234 at gmail.com
Sun Mar 6 22:27:22 EST 2016
1. What are the rules for using __del__ besides: 'don't use it'.
2. What happens when I SystemExit? __del__ and gc are not invoked when I
SystemExit and there's a circular reference - but why? The OS is going
to reclaim the memory anyways so why be finicky about circular
references - why can't we go ahead and call __dell_ and run gc?
3.
import foo
def __del__(self, foo=foo):
foo.bar()
What happens here to prevent a NameError? Apparently without the foo=foo
a NameError can occur? But why? import foo creates a reference to the
object anyways so it's refcount will be above 0 anyways till __del__ is
called.
4. also, are method calls more efficient than function calls?
More information about the Python-list
mailing list