#13447: Make libsingular multivariate polynomial rings collectable
----------------------------------------------------------------+-----------
       Reporter:  nbruin                                        |         
Owner:                                                                          
 
           Type:  defect                                        |        
Status:  needs_work                                                             
  
       Priority:  major                                         |     
Milestone:  sage-5.4                                                            
     
      Component:  memleak                                       |    
Resolution:                                                                     
      
       Keywords:                                                |   Work 
issues:  Understand why sometimes `new_RingWrap` needs an incref and sometimes 
not
Report Upstream:  None of the above - read trac for reasoning.  |     
Reviewers:  Simon King                                                          
     
        Authors:  Nils Bruin, Simon King                        |     Merged 
in:                                                                           
   Dependencies:  #11521                                        |      
Stopgaps:                                                                       
    
----------------------------------------------------------------+-----------

Comment (by jpflori):

 Replying to [comment:29 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?
 '''Edit:''' Yes it would.
 FYI, the cdefed pointer _parent stuff was added in #12313.
 Have a look at http://trac.sagemath.org/sage_trac/ticket/12313#comment:13

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