Reference count access or better method?

Philip Swartzleonard starx at pacbell.net
Sun Jan 13 19:56:17 EST 2002


Alex Martelli || Sun 13 Jan 2002 03:17:45p:

> Philip Swartzleonard wrote:
>         ...
>> continual access. When no one else but the dictionary refernces the
>> object, i want to have the _option_ to purge it (just giving up on it
>> and deleting it from the dict is not what i want, it must have a
>> reference ... Is weekref what i want for something like this? Is there
>> a better way to 
> 
> Almost.  weakref.ref and .proxy do let you specify a callback, but that
> happens when the referent is no longer available.  You could wrap the
> referent into a highly-transparent-proxy, have all client code refer to
> the proxy, and when the proxy goes away and your weakref.ref to it
> triggers your callback, you still have the real object in hand.  I.e., 
> "there's no ill that can't be cured by another level of
> indirection":-). 
> 
> The highly transparent proxy can be built by automatic delegation, cfr
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52295

But what if it is then referenced again, how do i determine that change in 
state? If it helps, the intent is to sort of 'de-cache' things, so that if 
an object isn't used for some amount of time, it's memory (gl display list) 
is destroied, and then it's recreated if it's needed again. But i need the 
object--- for the textures example, their identity is determined by thier 
pathname, so i'm going to make a customized list that attempts to construct 
on first mention, but i can't create these objects from such simple data. 
Or... maybe i can... hm... i already store the paramters for the object, i 
could store them in a meta-object of some sort...

-- 
Philip Sw "Starweaver" [rasx] :: <nothing>



More information about the Python-list mailing list