M2
M2 copied to clipboard
memory leak
This code
engineMemory = value Core#"private dictionary"#"engineMemory"
needsPackage "RandomCanonicalCurves"
ps = () -> run ( "ps u " | toString processID () )
leak = c -> (
setRandomSeed "37862873";
g := 9;
p := 12347;
numEx := 40;
T := ZZ/p[t_0..t_(g-1)];
for i from 1 to 100 do (
IC := (random canonicalCurve)(g,T);
minimalBetti IC;
-- registerFinalizer (IC.cache.quotient,"--");
if c then IC.cache.quotient = null;
<< "." << flush;);
collectGarbage();
print engineMemory();
)
ps()
leak true
ps()
leak false
ps()
runnning under https://github.com/mikestillman/M2/tree/newres produces this totally perplexing result:
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
dan 75775 0.0 0.5 2917676 85244 s002 S+ 10:39AM 9:50.42 /Users/dan/src/M2/M2-Macaula
....................................................................................................size of each slabs = 2040
total engine space allocated = 0k
stash k total k in use size nalloc inuse highwater freed
Finalizations of new resolutions:
# of res objects constructed/deconstructed=(100,100) #left = 0
# of res objects constructed/deconstructed=(100,100) #left = 0
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
dan 75775 102.8 0.6 2932208 101080 s002 S+ 10:39AM 10:59.57 /Users/dan/src/M2/M2-Macaula
....................................................................................................size of each slabs = 2040
total engine space allocated = 0k
stash k total k in use size nalloc inuse highwater freed
Finalizations of new resolutions:
# of res objects constructed/deconstructed=(200,180) #left = 20
# of res objects constructed/deconstructed=(200,180) #left = 20
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
dan 75775 140.4 2.0 3177916 331080 s002 S+ 10:39AM 12:14.92 /Users/dan/src/M2/M2-Macaula
Solving it would improve memory performance a lot.
commit e7ee2bc4e5bd4978261c45987bb0e71da35cace9 will fix this
But we don't understand why.
This file gives a simpler example of the memory leak:
https://github.com/Macaulay2/Workshop-2016-Warwick/blob/master/memoryLeaks/leak3.m2
Almost any change to this example diminishes the leak, but it's hard to believe that libgc is so easily thwarted by multiple cycles in the graph of pointers between memory blocks. It's a mystery.
We set up the computation for the nonminimal resolution, but don't start it. Observe that a preparatory gb is computed for it, nevertheless.