getting the reference count of an object ...

Just just at xs4all.nl
Fri Mar 3 05:38:47 EST 2006


In article <mailman.2640.1141381374.27775.python-list at python.org>,
 Wildemar Wildenburger <wildemar at freakmail.de> wrote:

> ... how?
> 
> I'm writing an app that holds a public data dictionary from which other 
> objects obtain part of their __dict__ values so they all work on the 
> same dataset (yes I'm fiendishly clever and a constructor of unreadable 
> sentences (and code) ;)).
> 
> My problem is that I haven't found an easy way to determine if said 
> dictionary contents are still in use (so it is ok to delete them from 
> the dictionary). I've thought about creating a dict subclass that counts 
> the number of assignments and deletions but that seems cumbersome (an 
> bug-prone).
> 
> Is there a way to get the reference count of these datadict items? I 
> imagine that this would be a more stable implementation of such a feature.
> 
> Hope this gets my problem accross; if not just bash me and I'll 
> reformulate. I'm not the best of explainers.
> 
> Oh, and sorry if the solution to my problem is obvious (such as an 
> __refcount__ attribute or some stupid oversight like that).

Direct answer: sys.getrefcount()

Better answer: look at the weakref module, especially at the various 
Dict helper classes.

Just



More information about the Python-list mailing list