gc.get_objects()

Chris Angelico rosuav at gmail.com
Mon Sep 17 12:09:25 EDT 2012


On Tue, Sep 18, 2012 at 12:16 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> The __del__ method does not delete an object. Remember, objects are only
> deleted when there are no references to it. Otherwise you could have some
> code that tries to use a deleted object, and you would get a system crash
> or BSOD.

There is a conceptually viable alternative: destroy an object
immediately and force all references to it to become some sentinel
value (eg None). Python currently doesn't have this, but it would be
rather convenient at times. Could be part of a construct like 'with'
to say "make this, use it, and then dispose of it".

ChrisA



More information about the Python-list mailing list