[ZODB-Dev] Investigating a Zope reference leak... tracking objectcreation

Tim Peters tim at zope.com
Mon Jan 31 14:31:15 EST 2005


[Ben Last]
>> ... What I was after (and still am) is a way to track the creation of
>> *instances* of the Python class.

[Dieter Maurer]
> They can be created in three ways:
>
>  * in the normal way (when the constructor for the class is called)

Which you can hook by supplying an __init__.  You can also supply a __del__,
but keep it simple (in particular, don't try to access any attributes of
self in a __del__; if you do, then older versions of ZODB can get into an
infinite loop (it's not intended that persistent objects have __del__
methods)).

>  * when the ZODB instantiates a persistent reference with
>    the class info.
>
>    This happens in the method
>    "ZODB.Connection.Connection._persistent_load"
>
>  * when the ZODB directly looks up an oid.
>    This happens in the method
>    "ZODB.Connection.Connection.__getitem__".

And you cannot hook those directly.  You'll have to fiddle the code.  You're
probably only interested in paths that call __basicnew__() (which is unique
to ExtensionClass, and is the way a ghost (mostly stateless) object of an
ExtensionClass is created).  Note that _persistent_load() is called
indirectly, by cPickle (you won't find any Python code that calls it).



More information about the ZODB-Dev mailing list