#715: Parents probably not reclaimed due to too much caching
------------------------+---------------------------------------------------
Reporter: robertwb | Owner: somebody
Type: defect | Status: needs_info
Priority: major | Milestone: sage-5.0
Component: coercion | Keywords: weak cache coercion
Work_issues: | Upstream: N/A
Reviewer: | Author: Simon King
Merged: | Dependencies: #9138, #11900
------------------------+---------------------------------------------------
Comment(by SimonKing):
Replying to [comment:142 jpflori]:
> With the current implementation, Actions always use a weak ref for the
underlying set so that it can and will be garbage collected if it is not
strong refed elsewhere.
>
> You illustrate and mention that in some examples in action.pyx.
>
> You also modify an example involving Action and MatrixSpace to make sure
that no gc occurs.
Or rather: That it does not occur too late.
> I do not think this is the right solution, I mean that the user should
be able to use Action has before (and anyway it does not feel right to me
that you can create something that can magically disappear).
I believe that it is fine. Namely, what use would an action have if you do
not have any other strong reference to the underlying set S?
That's to say: You forgot S and ''all'' of its elements. But what use
would an action on S if you not even know to provide a single element of
S?
> You could also argue that nobody actually uses Actions directly (I do
not for example :) ), those who do will have to be careful.
I think so.
> * Add a big fat warning in Action documentation (red, in a bloc, at the
start, etc.)
OK, that would need more than the short remarks in my added examples.
> * Implement somehow an option to choose whether to use weak ref (which
will be set for the coercion model) or strong ones (set by default, so the
"normal" and previous behaviour will be the default one). It basically
mean passing an additional boolean somehow which will lead the
construction of underlying_set, be saved and modify the behavior of
underlying_set() (i.e. add () or not)
One could store the underlying set S either by
{{{
self.S = weakref.ref(S)
}}}
resulting in a weak reference, or by
{{{
self.S = ConstantFunction(S)
}}}
resulting in a strong reference.
The advantage is that `underlying_set()` could remain as it is. In
particular, we don't need to make the syntax (`return self.S` versus
`return self.S()`) depend on any any parameter used during
initialisation. Note that calling a `ConstantFunction` takes almost no
time.
However, it might even be faster to do
{{{
if self.use_weak_references:
return self.S()
else:
return self.S
}}}
where `self.use_weak_references` is a `cdef bint` parameter assigned
during initialisation.
I can't test it right now.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/715#comment:144>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.