#14711: Weak references in the coercion graph
-------------------------------------+-------------------------------------
Reporter: jpflori | Owner: davidloeffler
Type: defect | Status: needs_review
Priority: critical | Milestone: sage-6.2
Component: number fields | Resolution:
Keywords: memleak, number | Merged in:
field, QuadraticField | Reviewers: Nils Bruin, Jean-
Authors: Simon King, | Pierre Flori
Travis Scrimshaw, Jean-Pierre | Work issues:
Flori | Commit:
Report Upstream: N/A | ea58b22f0bf2652e7d04b3d55e6217dcb8732cdf
Branch: | Stopgaps:
public/ticket/14711 |
Dependencies: |
-------------------------------------+-------------------------------------
Comment (by SimonKing):
PS: This "`CopyOnPrint`" would only provide the string representation of
the map. The whole error message would then be a lazy format string, such
that the copy would really ''only'' happen when printing the error
message.
Proof of concept:
{{{
sage: class CopyOnPrint:
....: def __init__(self, x):
....: self.x = x
....: def __repr__(self):
....: print "Now a copy is taken"
....: return repr(x.__copy__())
....:
sage: O = CopyOnPrint(x)
sage: O
Now a copy is taken
x
sage: msg = "The map %s is doomed"%O
Now a copy is taken
}}}
The last line shows that the copy happens even though the message is not
printed. However, when combined with a lazy format string, the behaviour
is as intended:
{{{
sage: from sage.misc.lazy_format import LazyFormat
sage: lazy_msg = LazyFormat("The map %s is doomed")%O
}}}
So, the message is created without copying, but copying happens when
printing the message:
{{{
sage: lazy_msg
Now a copy is taken
The map x is doomed
}}}
--
Ticket URL: <http://trac.sagemath.org/ticket/14711#comment:237>
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.
For more options, visit https://groups.google.com/d/optout.