Iterating over objects of a class

Kottiyath n.kottiyath at gmail.com
Wed Dec 24 14:08:27 EST 2008


On Dec 24, 11:48 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
wrote:
> En Wed, 24 Dec 2008 16:18:55 -0200, Kottiyath <n.kottiy... at gmail.com>  
> escribió:
>
> >> The other thing to remember is that because the 'registry' contains
> >> references to the instances, they won't be garbage collected.
>
> > Is there any other way out in this case?
> > I have factory methods - and I have to loop over them - sort of Chain
> > of Responsibility pattern.
> > Having a registry inside the class instance and looping through them
> > was the only clean thing I could think of.
> > I understand that garbage collection would be an issue - but is there
> > any way out?
>
> You may keep all that structures - just use weak references (see the  
> weakref module).
> There isn't a WeakList nor WeakSet out-of-the-box but you may use a  
> WeakKeyDictionary (set the value to anything, None by example).
>
> --
> Gabriel Genellina

Thank you very much, Gabriel.
I am very thankful to everyone.



More information about the Python-list mailing list