[GAP Forum] memory management in GAP

Stephen Linton sal at mcs.st-andrews.ac.uk
Mon Nov 15 23:56:04 GMT 2010


On 15 Nov 2010, at 23:08, R. Keith Dennis wrote:

> Hi again - I have some questions regarding how one manages
> memory usage in GAP - the manual doesn't seem to answer my
> questions.
> 
> 1.  Is it possible to enlarge the memory available in GAP from 
> the "inside"?  That is, if one gets an out of memory error, is
> it possible to do something from the GAP command line that is
> more or less equivalent to starting with the -o option set to
> a larger value?
> 
> My presumption is "no" since this didn't seem to be addressed in the
> manual.

At the moment no, although this is on the list to fix in a future version.
> 
> 2.  Is there a way to force GAP to release memory it has used in a 
> computation?  It appears that GAP hangs onto the memory & it can only
> be recovered by killing GAP and starting over again.
> 
> I have a program that in a single case creates a table with say 1G of
> data & uses up 30G of memory (in a 48G machine).  The program
> finishes, I save the data, reset the variable containing the 1G of
> data to [], and then wish to do the next case.  GAP does not release
> the memory (according to top, according to GasmanStatistics &
> according to its behavior).  I kill GAP, reload program & run the next
> case with no problem.  Why must I do this?  Ok, am I making some
> error?

You should not need to do this. GAP should release the memory at its next full garbage collection. If you want to hasten this process, you can call
GASMAN("coillect");
to trigger an immediate collection.

If your large data structure is not being freed in a garbage collection, it must be because GASMAN thinks it
is still accessible. There are a few ways this might happen --

one of the variables last, last2 or last3 might refer to it
it might contain data which is referenced from one of the pieces of information that GAP routinely caches, such as finite fields
It might be an attribute of an object that stores its attribute values

Less plausibly, but not impossibly, there may be some binary value on the stack or somewhere which just happens to look 
like a pointer to the object, although actually it's a C integer or something. In this case GASMAN will act "conservatively" and not free the object, but this is
very rare.

Steve

> 
> Is there a way to use Gasman, or something else, to tell GAP to release
> the memory it used?  I couldn't find this in the manual.  Is it there?
> 
> Are there tips for writing GAP code that avoids problems of this type?
> Any suggestions are most welcome!
> 
> Keith
> 
> 
> 
> 
> _______________________________________________
> Forum mailing list
> Forum at mail.gap-system.org
> http://mail.gap-system.org/mailman/listinfo/forum




More information about the Forum mailing list