Simon Pickles <si*******@hotmail.comwrote:
Is is possible to access the refcount for an object?
>>import sys
sys.getrefcount(42)
6
Ideally, I am looking to see if I have a refcount of 1 before calling del
That's a pointless exercise: you probably don't understand what del does.
All that del does is remove one reference from an object, either by
removing a name from the namespace, or by removing a reference from
something like a list. 'del x' does NOT destroy the object referenced by x,
unless it happens that there are no other references to the object.
Also note that the only time you will see a reference count of 1 is on an
object which you cannot otherwise access (the only reference is being used
for the call to getrefcount()):
>>x = 99999
sys.getrefcount(x)
2