Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Libsingular memory management (memory leak?)
PostPosted: Tue Feb 06, 2018 11:57 pm 

Joined: Tue Feb 06, 2018 6:44 pm
Posts: 4
I'm struggling with a memory clean up/possible memory leak problem. Calling simple code like
Code:
ring r = ...;
ideal i = ...;
slimgb(i);
kill r;

builds up (variable) memory (I'm checking memory(0) and also direct system output coincides with this observation), although I would expect that after "kill r" everything is cleaned up (there are no further variables and processes defined). I realized it since I'm calling code like that a lot of times inside the same (c++) session. It seems to me that memory is lost whenever something is printed (output and info/warning messages). My question though is two-fold:
Is this actually a bug in the code or I'm I forgetting to clean up something? I'm mainly interested to have this properly working through the c++ interface. (I'm using interpreter functions directly from within c++, like iiAllStart), the same memory loss happens also happens when called from the singular binary.
Or is there a way to reset the whole interpreter environment from within c++ without a full restart?

(If you're interested: I'm actually building a simple Singular interface for Mathematica via its LibraryLink function to have fast interaction with Singular. Everything except from this memory problem works like a beauty.)


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Libsingular memory management (memory leak?)
PostPosted: Wed Feb 07, 2018 4:00 pm 

Joined: Wed May 25, 2005 4:16 pm
Posts: 275
There several things still taking memory legally:
- standard.lib is always loaded (see listvar(proc))
- the kernel introduces some variables (Top, ZZ, QQ, etc.)
- polynomials rings over ZZ/p (for p<2^15) create 2 tables of size 2*p bytes
which is cached for the next ring creation
- the last output is cached (to be accessed via _) -
this cache is cleared, if the value depends on a ring and the ring is killed.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Libsingular memory management (memory leak?)
PostPosted: Wed Feb 07, 2018 6:00 pm 

Joined: Tue Feb 06, 2018 6:44 pm
Posts: 4
If I understand correctly theses things don't grow indefinitely (i.e. once they are initialized they stay more or less the same size depending on their current value), so that's not a problem for me.
To illustrate where I have memory building up consider the following code:
Code:
ring r = (0,a), (x), dp;
ideal i = x, x;
slimgb(i);
kill r;
memory(0);

Running this piece of code several times inside the same session expands the used memory after every repetition. Since I run code like that a lot of times in the same session I eventually run out of memory. One observation that I made is that there is no memory increase if I drop the constant 'a' in the ring definition. I also checked out other examples and I couldn't not find a pattern in which cases there is memory building up.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Libsingular memory management (memory leak?)
PostPosted: Thu Feb 08, 2018 5:05 pm 

Joined: Wed May 25, 2005 4:16 pm
Posts: 275
The example you provide does not have a memory leak
in the current (development) version of Singular


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Libsingular memory management (memory leak?)
PostPosted: Thu Feb 08, 2018 8:25 pm 

Joined: Tue Feb 06, 2018 6:44 pm
Posts: 4
Awesome, I just pulled the newest version and it indeed works nicely. Thanks a lot!


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

It is currently Fri May 13, 2022 11:03 am
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group