On Mon, Jul 2, 2018 at 11:55 PM Travis Scrimshaw <[email protected]> wrote:
>
> Hi everyone,
>    By my recollection, we are using strong references for keys in the 
> UniqueRepresentation cache (and weak references for the values). Is there a 
> particular reason why we are not using weak references for the keys as well? 
> If my understanding is correct, this would get rid of a number of memory leak 
> issues. (The context of this is Jeroen asked me about the possibility of 
> implementing a weak key and value global cache to solve 
> https://trac.sagemath.org/ticket/25752, and I was worried we would easily run 
> into memory leaks using the usual UR type cache.)

I kept meaning to look into why the UniqueRepresentation cache is so
prone to memory leaks.  It's really using strong references for the
keys?  Because that would certainly explain it...  I don't see why it
shouldn't use weakrefs but I don't know if there's any history to
that...

I guess the idea of using weak references for the values was just to
ensure that objects that aren't in use somewhere don't hang around in
memory, and it makes sense to still have that usage I think.  But
perhaps what you need is some kind of WeakKeyValueDictionary, which
doesn't exist in the stdlib, which might be partly why this wasn't
done in the first place.

Also, just using weakrefs for the keys alone is not sufficient.  If
the cache key is a tuple (which I think it always is in the case of
UniqueRepresentation) then you can't just have a weakref to that
tuple, but also to all its members, and a mechanism to resolve all
weakrefs in the key.  I'm not really sure how that would work though.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to