#11521: Memleak when resolving the action of Integers on an Elliptic Curve
------------------------+---------------------------------------------------
   Reporter:  jpflori   |          Owner:  robertwb    
       Type:  defect    |         Status:  needs_review
   Priority:  major     |      Milestone:  sage-5.0    
  Component:  coercion  |       Keywords:  sd35        
Work_issues:            |       Upstream:  N/A         
   Reviewer:            |         Author:  Simon King  
     Merged:            |   Dependencies:  #11900 #715 
------------------------+---------------------------------------------------

Comment(by SimonKing):

 It turns out that the failing test had in fact a wrong design. It was:
 {{{
             sage: import gc
             sage: from sage.rings.polynomial.multi_polynomial_libsingular
 import MPolynomialRing_libsingular
             sage: from sage.libs.singular.ring import ring_refcount_dict
             sage: n = len(ring_refcount_dict)
             sage: R = MPolynomialRing_libsingular(GF(547), 2, ('x', 'y'),
 TermOrder('degrevlex', 2))
             sage: len(ring_refcount_dict) == n + 1
             True

             sage: Q = copy(R)   # indirect doctest
             sage: p = R.gen(0) ^2+R.gen(1)^2
             sage: q = copy(p)
             sage: del R
             sage: del Q
             sage: del p
             sage: del q
             sage: gc.collect() # random output
             sage: len(ring_refcount_dict) == n
             True
 }}}

 Hence, before n is defined, no garbage collection takes place. This is, of
 course, not correct: The ring_refcount_dict may contain references to a
 ring created in another doctest, that is only garbage collected in the
 line before `len(ring_refcount_dict)==n`.

 In other words: The test did not fail ''because'' there was a memory leak.

 When I insert a garbage collection right before the definition of n, the
 test works, and in addition the warning about `AttributeError` being
 ignored vanishes.

 The patch fixes the memory leak caused by a strong homset cache (which was
 not addressed by #715):
 {{{
 sage: for p in prime_range(10^3):
 ....:     K = GF(p)
 ....:     a = K(0)
 ....:
 sage: import gc
 sage: gc.collect()
 3128
 sage: LE = [x for x in gc.get_objects() if  isinstance(x,type(K))]
 sage: LE
 [Finite Field of size 2, Finite Field of size 997]
 }}}
 The patch adds a new doctest demonstrating that it is fixed.

 Needs review!

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11521#comment:117>
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.

Reply via email to