index all instances by id - a memory leak?

Jason Scheirer jason.scheirer at gmail.com
Thu Oct 2 07:35:21 CEST 2008


On Oct 1, 10:01 pm, Dan Barbus <dan.bar... at gmail.com> wrote:
> On Oct 2, 7:54 am, Dan Barbus <dan.bar... at gmail.com> wrote:
>
>
>
> >     def getItemById(id):
> >         return _itemsById[id]
>
> I just saw that this won't compile. Still, ignoring this, I thing the
> purpose of the code is pretty clear.
>
> Thanks for any feedback.

Check the weakref module, you can create a WeakValueDictionary which
will not increment the refcount of the value, and will return None
after it's been garbage collected.



More information about the Python-list mailing list