Hi Nils, On 2013-02-04, Nils Bruin <nbr...@sfu.ca> wrote: > I don't see how we can avoid this. In principle the coercion maps > don't need to hold references to their domain and codomain, because > these are part of the key by which they are looked up.
I am thinking about the following layout: Let D and C be domain and codomain of a coercion or conversion map phi. Assume that the user does not keep a strong reference to phi. Aim: If the user does not keep a strong reference to D *or* no strong reference to C then phi should become collectable. * The cache for phi should be located in C (that's currently the case) with a strong reference to phi, using D as a weak key. * phi should have a strong reference to its codomain C (that's currently the case). * phi should only have a weak reference to its domain D (that's new). Hence, C and phi are part of a strong reference cycle, but D is not part of that cycle. Let's see what happens if no strong reference (outside of that cycle) is kept towards C resp. D: * No external strong reference to C means that the only strong references to C come from phi, and the only strong references to phi come from the coercion dict stored as an attribute of C. Hence, the cyclic garbage collector can collect both C and phi. * No external strong reference to D means that the map phi can be deleted from C's coercion dictionary: D is a *weak* key, and phi is not able to keep D alive, as it only stores a weak reference to its domain. But is a weak reference to the domain of a map really enough? I think it is. Namely, what do we want with a map? Well, we want to apply it to some elements of its domain. But if we have (by strong reference) some elements of phi's domain D, then D is kept alive by these elements. But if we do not keep elements of D, then phi is useless (there is nothing it could be applied to), and thus we can easily live with phi and D becoming collectable. Do you think this makes sense? Cheers, Simon -- 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 sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at http://groups.google.com/group/sage-devel?hl=en. For more options, visit https://groups.google.com/groups/opt_out.