#13447: Make libsingular multivariate polynomial rings collectable
-------------------------------------------------------+--------------------
       Reporter:  nbruin                               |         Owner:  rlm    
                       
           Type:  defect                               |        Status:  
needs_info                    
       Priority:  major                                |     Milestone:  
sage-5.4                      
      Component:  memleak                              |    Resolution:         
                       
       Keywords:                                       |   Work issues:  Input 
from libsingular experts
Report Upstream:  Reported upstream. No feedback yet.  |     Reviewers:         
                       
        Authors:                                       |     Merged in:         
                       
   Dependencies:                                       |      Stopgaps:         
                       
-------------------------------------------------------+--------------------

Comment (by SimonKing):

 Replying to [comment:27 nbruin]:
 > We have:
 > {{{
 >     def __dealloc__(self):
 >         celement_destruct(&self.x,
 get_cparent((<Polynomial_template>self)._parent))
 > }}}
 > and for us:
 > {{{
 > get_cparent(parent) == <ntl_ZZ_pEContext_class>(parent._modulus)
 > }}}
 > The `_parent` attribute is a cython slot.

 Interestingly, there is no complaint about a missing attribute `_parent`.
 It is `_modulus` that is missing.

 > However, it holds a reference to a python-managed object, so I think
 cython ensures it's properly taken into account in GC cycle counting. But
 that would suggest to me python could clear this slot to break cycles! So
 in that case, `Polynomial_template` is never safe. It could be I'm wrong,
 however.

 I think you are right. The `__dealloc__` of `Polynomial_template` is
 unsafe, unless polynomial rings will stay in memory forever. But I'd love
 to hear that we are wrong, because otherwise each polynomial would need a
 pointer to the c-data expected to be returned by
 `get_cparent((<Polynomial_template>self)._parent)`, and we'd need to take
 into account reference counting for the c-parent during creation and
 deletion of polynomials.

 Or perhaps there is a way out. We have a polynomial ring R and we have
 some elements a,b,c,... Each element points to R, and R points to some of
 its elements, namely to its generators. The problem is that deallocation
 of the elements is only possible as long as R is alive.

 If we'd manually incref R upon creation of an element x, decrefing R when
 x gets deallocated, then we would ensure that R will survive until the
 last of its elements is deleted. Or would that mean that the elements will
 survive as well, because of the reference from R to its generators?

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/13447#comment:29>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to