# HG changeset patch
# User JeanPierre Flori <jeanpierre.flor@ssi.gouv.fr>
# Date 1332265553 3600
# Node ID 6ae87d84ec503b28ab3a7240a9dd7becfe63c803
# Parent e7d3eef7fcfd286a6483d9daf2eafebd518b50b0
#11521: Reviewer patch
diff git a/sage/categories/homset.py b/sage/categories/homset.py
a

b


1   """ 
 1  r""" 
2  2  Homsets 
3  3  
 4  The class :class:`Hom` is the base class used to represent sets of morphisms 
 5  between objects of a given category. 
 6  :class:`Hom` objects are usually "weakly" cached upon creation so that they 
 7  don't have to be generated over and over but can be garbage collected together 
 8  with the corresponding objects when these are are not stongly ref'ed anymore. 
 9  
 10  EXAMPLES: 
 11  
 12  In the following, the :class:`Hom` object is indeed cached:: 
 13  
 14  sage: K = GF(17) 
 15  sage: H = Hom(ZZ, K) 
 16  sage: H 
 17  Set of Homomorphisms from Integer Ring to Finite Field of size 17 
 18  sage: H is Hom(ZZ, K) 
 19  True 
 20  
 21  Nonetheless, garbage collection occurs when the original references are 
 22  overwritten:: 
 23  
 24  sage: for p in prime_range(200): 
 25  ... K = GF(p) 
 26  ... H = Hom(ZZ, K) 
 27  ... 
 28  sage: import gc 
 29  sage: _ = gc.collect() 
 30  sage: from sage.rings.finite_rings.finite_field_prime_modn import FiniteField_prime_modn as FF 
 31  sage: L = [x for x in gc.get_objects() if isinstance(x, FF)] 
 32  sage: len(L) 
 33  2 
 34  sage: L 
 35  [Finite Field of size 2, Finite Field of size 199] 
 36  
4  37  AUTHORS: 
5  38  
6  39   David Kohel and William Stein 
… 
… 

29  62  # http://www.gnu.org/licenses/ 
30  63  #***************************************************************************** 
31  64  
32   import weakref 
33   
34  65  from sage.categories.category import Category 
35  66  import morphism 
36  67  from sage.structure.parent import Parent, Set_generic 
… 
… 

81  112  sage: Hom(FreeModule(QQ,1), FreeModule(ZZ,1)) 
82  113  Set of Morphisms from Vector space of dimension 1 over Rational Field to Ambient free module of rank 1 over the principal ideal domain Integer Ring in Category of vector spaces over Rational Field 
83  114  
84   Here, we test against a memory leak that has been fixed at #11521 by using 
85   a weak cache:: 
 115  Here, we test against a memory leak that has been fixed at :trac:`11521` by 
 116  using a weak cache:: 
86  117  
87  118  sage: for p in prime_range(10^5): 
88  119  ... K = GF(p) 