[sage-devel] Re: releasing memory in compiled components

2017-01-10 Thread kcrisman


On Monday, January 9, 2017 at 9:52:37 AM UTC-5, John Cremona wrote:
>
> In a reply to question 36225 at 
> https://ask.sagemath.org/question/36225/memory-leak-with-modular-symbols/ 
> (my reply was deleted by the system so you cannot read it) I offered 
> to try to help by asking here how to do somthign I don't know how to 
> do. 
>
> This apparently was taken care of - not sure why your reply would have 
ended up in the review queue. 

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-devel] Re: releasing memory in compiled components

2017-01-09 Thread Jeroen Demeyer

On 2017-01-09 23:11, Jean-Pierre Flori wrote:

I guess that to do that you need an argless constructor which does not
seem to be the case here.


Does the C++ class not have an argless constructor or is it just not 
declared in the Cython file?


--
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-devel] Re: releasing memory in compiled components

2017-01-09 Thread Jean-Pierre Flori


On Monday, January 9, 2017 at 10:33:49 PM UTC+1, Jeroen Demeyer wrote:
>
> On 2017-01-09 16:45, Jean-Pierre Flori wrote: 
> > I guess you want to free the memory allocated here: 
> > * 
> > 
> https://github.com/sagemath/sage/blob/master/src/sage/libs/eclib/newforms.pyx#L112
>  
>
> Alternatively, instead of a pointer you could store the object itself in 
> the Python class. Then you wouldn't use new and wouldn't need to delete 
> anything. I'm not at all saying that this is the best option, it's just 
> something to consider... 
>
I guess that to do that you need an argless constructor which does not seem 
to be the case here. 

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-devel] Re: releasing memory in compiled components

2017-01-09 Thread Jeroen Demeyer

On 2017-01-09 16:45, Jean-Pierre Flori wrote:

I guess you want to free the memory allocated here:
*
https://github.com/sagemath/sage/blob/master/src/sage/libs/eclib/newforms.pyx#L112


Alternatively, instead of a pointer you could store the object itself in 
the Python class. Then you wouldn't use new and wouldn't need to delete 
anything. I'm not at all saying that this is the best option, it's just 
something to consider...


--
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


[sage-devel] Re: releasing memory in compiled components

2017-01-09 Thread Volker Braun
On Monday, January 9, 2017 at 9:08:46 PM UTC+1, Jean-Pierre Flori wrote:
>
> Isn't that the correct way to trigger Cytohn writin down an explicit call 
> to the destructor?
>

Right, every new'ed C++ object should be del'ed somewhere in the program. I 
misunderstood what you meant.


-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-devel] Re: releasing memory in compiled components

2017-01-09 Thread David Roe
On Mon, Jan 9, 2017 at 3:08 PM, Jean-Pierre Flori  wrote:

>
>
> On Monday, January 9, 2017 at 7:03:57 PM UTC+1, Volker Braun wrote:
>>
>> On Monday, January 9, 2017 at 4:45:19 PM UTC+1, Jean-Pierre Flori wrote:
>>>
>>> You can just use the Python "del" operator and Cython should translate
>>> it to a destructor call.
>>>
>>
>> No, there is the following caveat when cyclic Python references are
>> involved:
>>
>> __dealloc__ is always called, but there is no guarantee that pure Python
>> attributes are still set (they may be cleared, that is, set to None, in
>> order to break cycles). Cython (cdef) attributes are still set.
>>
>> __del__ will not always be called, some garbage objects are skipped to
>> break cycles. If __del__ is being called then all Python attributes are
>> still set.
>>
>> TLDR: use __dealloc__ to destroy wrapped C++ objects.
>>
> I meat write with __dealloc__:
> cdef __dealloc__:
> blablabla
> 
> if I_made_sure_new_was_called_and_constructor_got_called:
> del my_cdefed_c++_pointer_which_has_been_allocated_with_new
>
> Isn't that the correct way to trigger Cytohn writin down an explicit call
> to the destructor?
>

Yes.  If you use sig_malloc you should use sig_free instead.  Note also
that it's def __dealloc__ not cdef __dealloc__, since __dealloc__ is a
Python special method.
David

> --
> You received this message because you are subscribed to the Google Groups
> "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-devel+unsubscr...@googlegroups.com.
> To post to this group, send email to sage-devel@googlegroups.com.
> Visit this group at https://groups.google.com/group/sage-devel.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


[sage-devel] Re: releasing memory in compiled components

2017-01-09 Thread Jean-Pierre Flori


On Monday, January 9, 2017 at 7:03:57 PM UTC+1, Volker Braun wrote:
>
> On Monday, January 9, 2017 at 4:45:19 PM UTC+1, Jean-Pierre Flori wrote:
>>
>> You can just use the Python "del" operator and Cython should translate it 
>> to a destructor call.
>>
>
> No, there is the following caveat when cyclic Python references are 
> involved:
>
> __dealloc__ is always called, but there is no guarantee that pure Python 
> attributes are still set (they may be cleared, that is, set to None, in 
> order to break cycles). Cython (cdef) attributes are still set.
>
> __del__ will not always be called, some garbage objects are skipped to 
> break cycles. If __del__ is being called then all Python attributes are 
> still set.
>
> TLDR: use __dealloc__ to destroy wrapped C++ objects.
>
I meat write with __dealloc__:
cdef __dealloc__:
blablabla

if I_made_sure_new_was_called_and_constructor_got_called:
del my_cdefed_c++_pointer_which_has_been_allocated_with_new

Isn't that the correct way to trigger Cytohn writin down an explicit call 
to the destructor?

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


[sage-devel] Re: releasing memory in compiled components

2017-01-09 Thread Volker Braun
On Monday, January 9, 2017 at 4:45:19 PM UTC+1, Jean-Pierre Flori wrote:
>
> You can just use the Python "del" operator and Cython should translate it 
> to a destructor call.
>

No, there is the following caveat when cyclic Python references are 
involved:

__dealloc__ is always called, but there is no guarantee that pure Python 
attributes are still set (they may be cleared, that is, set to None, in 
order to break cycles). Cython (cdef) attributes are still set.

__del__ will not always be called, some garbage objects are skipped to 
break cycles. If __del__ is being called then all Python attributes are 
still set.

TLDR: use __dealloc__ to destroy wrapped C++ objects.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


[sage-devel] Re: releasing memory in compiled components

2017-01-09 Thread Jean-Pierre Flori
I guess you want to free the memory allocated here:
* 
https://github.com/sagemath/sage/blob/master/src/sage/libs/eclib/newforms.pyx#L112

You should add a __dealloc__ method to your class and free the memory there:
* 
http://docs.cython.org/en/latest/src/userguide/special_methods.html#finalization-method-dealloc
You can just use the Python "del" operator and Cython should translate it 
to a destructor call.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.