Skip to content

Commit

Permalink
Trac #19244: Broken doctest in src/sage/categories/fields.py
Browse files Browse the repository at this point in the history
The following doctest from #14058 breaks sometimes. I have seen it
happen twice, but it's hard to reproduce:
{{{
sage -t --long src/sage/categories/fields.py
**********************************************************************
File "src/sage/categories/fields.py", line 104, in
sage.categories.fields.Fields.__contains__
Failed example:
    len([X for X in gc.get_objects() if isinstance(X,
sage.rings.finite_rings.integer_mod_ring.IntegerModRing_generic)]) - n
Expected:
    0
Got:
    -1
**********************************************************************
}}}

URL: http://trac.sagemath.org/19244
Reported by: jdemeyer
Ticket author(s): Simon King
Reviewer(s): Jeroen Demeyer
  • Loading branch information
Release Manager authored and vbraun committed Sep 21, 2015
2 parents 019923e + c289fb0 commit 7aec32d
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/sage/categories/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,27 @@ def __contains__(self, x):
sage: GR in Fields()
True
The following tests against a memory leak fixed in :trac:`13370`::
The following tests against a memory leak fixed in :trac:`13370`. In order
to prevent non-deterministic deallocation of fields that have been created
in other doctests, we introduced a strong reference to all previously created
uncollected objects in :trac:`19244`. ::
sage: import gc
sage: _ = gc.collect()
sage: n = len([X for X in gc.get_objects() if isinstance(X, sage.rings.finite_rings.integer_mod_ring.IntegerModRing_generic)])
sage: permstore = [X for X in gc.get_objects() if isinstance(X, sage.rings.finite_rings.integer_mod_ring.IntegerModRing_generic)]
sage: n = len(permstore)
sage: for i in prime_range(100):
....: R = ZZ.quotient(i)
....: t = R in Fields()
First, we show that there are now more quotient rings in cache than before::
sage: len([X for X in gc.get_objects() if isinstance(X, sage.rings.finite_rings.integer_mod_ring.IntegerModRing_generic)]) > n
True
When we delete the last quotient ring created in the loop and then do a garbage
collection, all newly created rings vanish::
sage: del R
sage: _ = gc.collect()
sage: len([X for X in gc.get_objects() if isinstance(X, sage.rings.finite_rings.integer_mod_ring.IntegerModRing_generic)]) - n
Expand Down

0 comments on commit 7aec32d

Please sign in to comment.