diff --git a/src/sage/categories/fields.py b/src/sage/categories/fields.py index 795f5275b0a..a57a52e1504 100644 --- a/src/sage/categories/fields.py +++ b/src/sage/categories/fields.py @@ -93,18 +93,19 @@ def __contains__(self, x): 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, :trac:`19244` disables garbage collection until we really - want it to happen. :: + in other doctests, we introduced a strong reference to all previously created + uncollected objects in :trac:`19244`. :: sage: import gc sage: _ = gc.collect() - sage: gc.disable() - 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() + sage: len([X for X in gc.get_objects() if isinstance(X, sage.rings.finite_rings.integer_mod_ring.IntegerModRing_generic)]) > n + True sage: del R - sage: gc.enable() 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 0