Skip to content

Commit

Permalink
Trac #9129: sqrt memory leaks
Browse files Browse the repository at this point in the history
cf http://groups.google.com/group/sage-
support/browse_thread/thread/8c18b2b91004c35a#
{{{
m = get_memory_usage()
i=0
while True:
    i+=1
    a = 2.sqrt()
    if i%1000==0:
        print get_memory_usage(m)
}}}

URL: http://trac.sagemath.org/9129
Reported by: zimmerma
Ticket author(s): Volker Braun
Reviewer(s): Marc Mezzarobba
  • Loading branch information
Release Manager authored and vbraun committed Apr 12, 2014
2 parents d351d40 + 42a4f7f commit 3b94c5f
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/sage/symbolic/tests.py
@@ -0,0 +1,42 @@
"""
Tests for the Sage/Pynac interaction
"""

#*****************************************************************************
# Copyright (C) 2013 Volker Braun <vbraun.name@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************


def rational_powers_memleak():
"""
Check that there is no memory leak in rational powers
OUTPUT:
Boolean. Whether the memory leak was detected.
See :trac:`9129`.
EXAMPLES::
sage: from sage.symbolic.tests import rational_powers_memleak
sage: rational_powers_memleak()
False
"""
from sage.rings.all import ZZ
import gc
gc.collect()
c0 = sum(1 for obj in gc.get_objects())
for i in range(1000):
a = ZZ(2).sqrt()
gc.collect()
c1 = sum(1 for obj in gc.get_objects())
# Test that we do not leak an object at each iteration
return (c1 - c0) >= 1000

0 comments on commit 3b94c5f

Please sign in to comment.