#16600: Further Free* cleanup
------------------------------+------------------------
       Reporter:  nthiery     |        Owner:
           Type:  task        |       Status:  new
       Priority:  major       |    Milestone:  sage-6.3
      Component:  categories  |   Resolution:
       Keywords:              |    Merged in:
        Authors:              |    Reviewers:
Report Upstream:  N/A         |  Work issues:
         Branch:              |       Commit:
   Dependencies:              |     Stopgaps:
------------------------------+------------------------

Comment (by nbruin):

 Keep in mind to avoid memory leaks. Currently we have one that can be
 avoided, but your proposed syntax would make it harder:
 {{{
 sage: FreeAlgebra(GF(5),['a','b']).category()
 Category of algebras with basis over Finite Field of size 5
 }}}
 Since categories do not get garbage collected (and given their strong
 interconnections, never will: see how much trouble it takes to keep
 parents somewhat collectable in the face of the coercion model), you'll
 run out of memory  when you make algebras over a whole bunch of finite
 fields sequentially. We have a solution to this (as you're well aware,
 since you helped with the implementation):
 {{{
 sage: PolynomialRing(GF(5),['x','y']).category()
 Join of Category of unique factorization domains and Category of
 commutative algebras over (finite fields and subquotients of monoids and
 quotients of semigroups)
 sage: PolynomialRing(GF(5),['x','y']).category() is
 PolynomialRing(GF(7),['x','y']).category()
 True
 }}}
 The category name looks absolutely horrible, but note that there's no
 explicit mention of the base ring. Indeed, the second line confirms that
 different base rings lead to the same category.

 We could change `FreeAlgebra(GF(5),['a','b'])` to do the same, but if I
 understand your proposal, you're thinking of changing that to
 `Algebras(GF(5)).free(['a','b'])` in which case you'd force the creation
 of the object that causes the memory leak.

 Your proposal `Algebras(QQ).Commutative().free(...)` for
 `PolynomialRing(QQ,...)` would make this even worse. I guess we could have
 `Algebras(Fields()).Commutative().free(QQ,...)` but I don't think that's
 very compelling. It requires the user to input `Fields()` and `QQ` in two
 different places and remember which goes where.

 By comparison, `FreeCommutativeAlgebra(QQ,...)` looks much more natural
 and makes it easy to only install a generic category by default (I'd say
 `PolynomialRing` is a shorter and more mnemonic alternative, though).

 I think you should address the memory leak issue and propose a syntax that
 encourages people to create objects that do not leak. I don't see how to
 do that by insisting that people should first instantiate a category.

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