[ZODB-Dev] Getting refcount of object in ZODB
Michel Pelletier
michel@digicool.com
Thu, 28 Jun 2001 11:30:33 -0700 (PDT)
Zope's control panel uses this code to show refcounts on the debug screen:
class Fake:
def locked_in_version(self): return 0
class DebugManager: ...
def refcount(self, n=None, t=(type(Fake), type(Acquisition.Implicit))):
# return class reference info
dict={}
for m in sys.modules.values():
for sym in dir(m):
ob=getattr(m, sym)
if type(ob) in t:
dict[ob]=sys.getrefcount(ob)
pairs=[]
append=pairs.append
for ob, v in dict.items():
if hasattr(ob, '__module__'):
name='%s.%s' % (ob.__module__, ob.__name__)
else: name='%s' % ob.__name__
append((v, name))
pairs.sort()
pairs.reverse()
if n is not None:
pairs=pairs[:n]
return pairs
This is just the normal in-memory refcounts. Did you want to know about
references between persistent objects in the storage, even if deactivated?
-Michel
On Thu, 28 Jun 2001, Greg Ward wrote:
> On 28 June 2001, Barry A. Warsaw said:
> > There's no advertised storage API way of getting this information
> > AFAIK. Different storages will maintain that information in different
> > ways (e.g. in Berkeley Full, it's maintained in a separate table --
> > well, two tables really, one for objects and the other for pickles ;).
>
> So is GC entirely the storage's responsibility, then? I.e., should I be
> poking about in FileStorage.py looking for rude back-door ways of
> getting the refcount?
>
> Or should I just say: Jim, given DB/Connection/FileStorage objects and
> either an OID or database object, how do I get the refcount for the
> object? And is that info available for ClientStorage as well? Or will
> I have to shutdown my ZEO server and access the database as a
> FileStorage to find this out?
>
> No, I do *not* intend to use this in an application, it's mainly
> curiosity. I want to make sure that an object I think is about to drop
> to zero refs really does drop to zero refs.
>
> Greg
>
> _______________________________________________
> For more information about ZODB, see the ZODB Wiki:
> http://www.zope.org/Wikis/ZODB/
>
> ZODB-Dev mailing list - ZODB-Dev@zope.org
> http://lists.zope.org/mailman/listinfo/zodb-dev
>