8.21 Clearing allocated memory (21.8.01)

8.21.1 emilio sanchez
8.21.2 David Harrington (22.8.01)
8.21.3 Jason C. Leach (22.8.01)
8.21.4 Robert Israel (22.8.01)
8.21.5 emilio sanchez (23.8.01)

8.21.1 emilio sanchez

I am using Maple 7.0 under Linux and I was wondering if there is an undocumented function which clears the memory allocated by Maple?

The user manual (?restart) states that it is only possible to free up the consumed memory by restarting Maple.

Since I have to perform several large calculations in nested loops which cause Maple to crash when the systems memory resources are exhausted (512MB).

It would be nice to reset Maple after each iteration in order to prevent it from crashing.

8.21.2 David Harrington (22.8.01)

try gc() after each iteration - this does garbage collection

8.21.3 Jason C. Leach (22.8.01)

What about re-setting some variables to NULL? With other programs, say in Java, doing this initiates garbage collection.

MyBigDataListList:=NULL;

8.21.4 Robert Israel (22.8.01)

I don’t know how you can expect to "clear the memory" without wiping out the data from your calculations in progress.

You can force garbage-collection with "gc", but Maple does this automatically every so often, so I don’t know if you’ll see an improvement by putting it in by yourself.

In some cases memory can be used up by a procedure that has "option remember" (but not "system"), so the procedure’s remember table keeps growing and is not reset by garbage collection.

You can check for such procedures with the help of "sniffmem" from my Maple Advisor Database, http://www.math.ubc.ca/israel/advisor.

What might help, if all else fails, is writing your data to a file, quitting and re-starting Maple, and reading the data back in.

8.21.5 emilio sanchez (23.8.01)

Jason C. Leach wrote: What about re-setting some variables to NULL?

I have not tried this, but since I always overwrite the same list with the new values, i.e. name[1]...name[60], I guess that this will not do anything.

The large memory uses seem to stem from internal data which Maple produces when executing the numerical Int command in a loop.

I will try sniffmem though I do not use any commands despite of for do and Int.

As a workaround I am using a shell script which restarts Maple with the corresponding parameters for the loops.

There is another (unintentional) advantage when using this method. The calculations run faster since the Int command seems to slow down when performed several times within a loop (maybe due to memory usage?).