4 ms·
All Python objects do get destructed at the end of the scope. The only exception are reference cycles, which get broken by a simple GC. Perl doesn't even have a
by lucian1900 13y ago
All Python objects do get destructed at the end of the scope. The only exception are reference cycles, which get broken by a simple GC. Perl doesn't even have a cycle detector, so cyclic references will never get destructed.
Python has a __del__ method that will be called on destruction, but is not guaranteed to be called in the case of cycles. That's what the with statement solves, guaranteeing destruction at the end of the block. It's common to have both __del__ and __exit__ call the same thing.
- Mithaldu 13y agoThey get destructed AFTER end of scope, not AT end of scope, regardless of the existence of cycles. See: http://eli.thegreenplace.net/2009/06/12/safely-using-destructors-in-python/ http://eli.thegreenplace.net/2009/06/12/safely-using-destruc...