#14159: Don't install callbacks on values of TripleDict, MonoDict
------------------------------+---------------------------------------------
Reporter: nbruin | Owner: tbd
Type: defect | Status: needs_work
Priority: major | Milestone: sage-5.8
Component: memleak | Resolution:
Keywords: | Work issues: Make part the coverage script
happy
Report Upstream: N/A | Reviewers: Nils Bruin
Authors: Simon King | Merged in:
Dependencies: #13387 | Stopgaps:
------------------------------+---------------------------------------------
Comment (by SimonKing):
Replying to [comment:19 nbruin]:
> tests OK for me. One tiny nitpick:
> - You're claiming that this fixes an extremely rare race condition wrt.
to GC. I'm actually not sure that it CAN occur for our particular use
(because our value has a strong reference to a key component). I think
your example on `TripleDictEraserOnValue` illustrates why we should prefer
checking this anyway. I hope we don't have to be this paranoid in the
future.
I thought you diagnosed that this was the cause of one problem we saw?
Such as:
1. Some parent X, Y give rise to a homset H, in a category C.
2. H and X get deleted, but the callbacks are not performed yet. A new
parent X2 is created, and by mere coincidence we have id(X)==id(X2).
3. The homset H2 with respect to X2, Y and C is created. It thus overrides
H in the cache.
4. Finally, the callback of H is performed, erasing H2 from the cache.
Boom
This is what I meant by a "rare racing condition".
Do you prefer that I erase this statement?
Thinking of it: Suppose we are now considering the callback of X, which,
in the above scenario, has not been called prior to the creation of X2.
Would it not delete the new item, too? So, shouldn't we add a test in
`TripleDictEraser.__call__(self, r)`, so that an item is deleted only if
one of the references from the keys of this item is identical with r?
> There's another one, that the `_cache[X,Y,category]=KeyedRef(...)`
statement is very fragile: If you make a mistake in typing the
`(id(X),id(Y),id(category))` you'll have a very hard to trace (and
possibly disastrous!) bug in your program. One solution would be to
encapsulate it in `TripleDict`, but the instantiation of the
`TripleDictEraserOnValue` would complicate the logic in `TripleDict`,
I wouldn't like to put this into `TripleDict`. After all, it is impossible
to prevent all thinkable typing mistakes.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/14159#comment:22>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" 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 http://groups.google.com/group/sage-trac?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.