[GAP Forum] Memory management with GAP

Mathieu Dutour Mathieu.Dutour at ens.fr
Wed Mar 23 13:43:27 GMT 2011


Dear all,

I run into memory problem with GAP and I want to reduce memory
expenses. And well I want to understand better how it works.

Suppose we have
MyFactorial:=function(n)
  local eList, i;
  eList:=[];
  for i in [1..n]
  do
    eList[i]:=i;
  od;
  return Product(eList);
end;

Then I presume that after a call to "MyFactorial" that "eList" is freed
after the call.

Now suppose I wrote
MyFunctions:=function(n)
  local eList, i, MyFactorial, MySum, a;
  for i in [1..n]
  do
    eList[i]:=i;
  od;
  a:=2;
  MyFactorial:=function()
    return Product(eList);
  end;
  MySum:=function()
    return Sum(eList);
  end;
  return rec(MyFactorial:=MyFactorial,
             MySum:=MySum);
end;
Then it is clear that when calling "MyFunctions", "eList" should not
be freed. But is "a" freed?

Now some general questions:
---Is there a way to know how much memory a variable occupies?
   The commands GasmanStatistics() is helpful but gives you only
   global information when what you want to know is more specific.
   Would it be possible to know how much memory a given variable
   uses? And the list of variables.
---It is said that the garbage collection of GAP is "very conservative"
   What does that really mean?
---In garbage collection, the problem is with cyclical links, 
   a->b and b->a. Well I do not even know how to create such links,
   let alone cyclical in GAP.
   What command could lead to such cyclical links?
   Is there a way to know if such cyclical links are indeed present
   in the variables of the user?

Best,

  Mathieu



More information about the Forum mailing list