Question About When Objects Are Destroyed (continued)

Tim Daneliuk info at tundraware.com
Sat Aug 5 17:41:59 EDT 2017


On 08/05/2017 11:16 AM, Ned Batchelder wrote:
> It uses
> reference counting, so most objects are reclaimed immediately when their
> reference count goes to zero, such as at the end of local scopes. 

Given this code:
class SomeObject:
 .....
for foo in somelist:
 a = SomeObject(foo)
 b = SomeObject(foo)
 c = SomeObject(foo)
 # Do something or other
 ...
 # Bottom of 'for' scope
Are you saying that each time a,b,c are reassigned to new instances of
SomeObject the old instance counts go to 0 and are immediately - as in
synchronously, right now, on the spot - removed from memory? My
understanding was (and I may well be wrong), that the reference count
does get decremented - in this case to 0 - but the *detection* of that
fact does not happen until the gc sweep looks through the heap for such
stale objects.


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /