#18897: Memory leak in eigenvalues method
---------------------------+------------------------
       Reporter:  slabbe   |        Owner:
           Type:  defect   |       Status:  new
       Priority:  major    |    Milestone:  sage-6.8
      Component:  memleak  |   Resolution:
       Keywords:           |    Merged in:
        Authors:           |    Reviewers:
Report Upstream:  N/A      |  Work issues:
         Branch:           |       Commit:
   Dependencies:           |     Stopgaps:
---------------------------+------------------------
Description changed by slabbe:

Old description:

> This method, inspired from the code of Nils Bruin posted in the sage-
> devel post [https://groups.google.com/d/msg/sage-
> devel/Jqi5f60j_lY/M7esZcJliZoJ Memory leaks on matrix creation?], shows
> some leak in the eigenvalues method for 4x4 and 5x5 integer matrices.
> Examples are below.
>
> {{{
> #!python
> def test(L, dim):
>     import gc
>     from collections import Counter
>     gc.collect()
>     pre={id(c) for c in gc.get_objects()}
>     for _ in range(100):
>         matrix(dim, L).eigenvalues()
>     gc.collect()
>     post=Counter(type(o) for o in gc.get_objects() if id(o) not in pre)
>     return [(k,v) for (k,v) in post.iteritems() if v>10]
> }}}
>
> An example with no leak::
> {{{
> #!python
>     sage: L = [1,0,0,1,0,0,1,1,0,0,0,1,2,0,0,1,0,0,2,0,0,0,0,0,1]
>     sage: test(L, 5)
>     []
> }}}
> Five forgotten polynomials::
> {{{
> #!python
>     sage: L = [1,1,0,1,0,1,2,1,1,0,0,1,2,0,0,1,1,0,2,0,0,0,0,0,1]
>     sage: test(L, 5)
>     [(<type 'sage.rings.polynomial.polynomial_compiled.univar_pd'>, 500)]
> }}}
> Twelve forgotten polynomials::
>
> {{{
> #!python
>     sage: L = [0,1,2,0,0,2,1,2,1,1,1,0,1,1,2,1,1,1,2,0,0,2,0,2,0]
>     sage: test(L, 5)
>     [(<type 'sage.rings.polynomial.polynomial_compiled.univar_pd'>,
> 1200)]
> }}}
> A 4 by 4 matrix with five forgotten polynomials::
> {{{
> #!python
>     sage: L = [0, 2, 0, 2, 2, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1]
>     sage: test(L, 4)
>     [(<type 'sage.rings.polynomial.polynomial_compiled.univar_pd'>, 500)]
> }}}
>
> Random ones::
>
> {{{
> #!python
>     sage: test([randint(0,100) for _ in range(9)], 3)
>     []
>     sage: test([randint(0,100) for _ in range(16)], 4)
>     [(<type 'sage.rings.polynomial.polynomial_compiled.univar_pd'>, 500)]
>     sage: test([randint(0,2) for _ in range(25)], 5)
>     [(<type 'sage.rings.polynomial.polynomial_compiled.univar_pd'>, 500)]
>     sage: test([randint(0,2) for _ in range(25)], 5)
>     [(<type 'sage.rings.polynomial.polynomial_compiled.univar_pd'>,
> 1200)]
>     sage: test([randint(0,2) for _ in range(25)], 5)
>     []
> }}}

New description:

 This method, inspired from the code of Nils Bruin posted in the sage-devel
 post [https://groups.google.com/d/msg/sage-devel/Jqi5f60j_lY/M7esZcJliZoJ
 Memory leaks on matrix creation?], shows some leak in the eigenvalues
 method for integer matrices of order larger or equal to 4. Examples are
 below.

 {{{
 #!python
 def test(L, dim):
     import gc
     from collections import Counter
     gc.collect()
     pre={id(c) for c in gc.get_objects()}
     for _ in range(100):
         matrix(dim, L).eigenvalues()
     gc.collect()
     post=Counter(type(o) for o in gc.get_objects() if id(o) not in pre)
     return [(k,v) for (k,v) in post.iteritems() if v>10]
 }}}

 An example with no leak::
 {{{
 #!python
     sage: L = [1,0,0,1,0,0,1,1,0,0,0,1,2,0,0,1,0,0,2,0,0,0,0,0,1]
     sage: test(L, 5)
     []
 }}}
 Five forgotten polynomials::
 {{{
 #!python
     sage: L = [1,1,0,1,0,1,2,1,1,0,0,1,2,0,0,1,1,0,2,0,0,0,0,0,1]
     sage: test(L, 5)
     [(<type 'sage.rings.polynomial.polynomial_compiled.univar_pd'>, 500)]
 }}}
 Twelve forgotten polynomials::

 {{{
 #!python
     sage: L = [0,1,2,0,0,2,1,2,1,1,1,0,1,1,2,1,1,1,2,0,0,2,0,2,0]
     sage: test(L, 5)
     [(<type 'sage.rings.polynomial.polynomial_compiled.univar_pd'>, 1200)]
 }}}
 A 4 by 4 matrix with five forgotten polynomials::
 {{{
 #!python
     sage: L = [0, 2, 0, 2, 2, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1]
     sage: test(L, 4)
     [(<type 'sage.rings.polynomial.polynomial_compiled.univar_pd'>, 500)]
 }}}

 Random ones::

 {{{
 #!python
     sage: test([randint(0,100) for _ in range(9)], 3)
     []
     sage: test([randint(0,100) for _ in range(16)], 4)
     [(<type 'sage.rings.polynomial.polynomial_compiled.univar_pd'>, 500)]
     sage: test([randint(0,2) for _ in range(25)], 5)
     [(<type 'sage.rings.polynomial.polynomial_compiled.univar_pd'>, 500)]
     sage: test([randint(0,2) for _ in range(25)], 5)
     [(<type 'sage.rings.polynomial.polynomial_compiled.univar_pd'>, 1200)]
     sage: test([randint(0,2) for _ in range(25)], 5)
     []
     sage: test([randint(0,100) for _ in range(36)], 6)
     [(<type 'sage.rings.polynomial.polynomial_compiled.univar_pd'>, 1400)]
 }}}

--

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

Reply via email to