Bug solved in 11.2
Bug introduced in 10.3 or earlier and persists through 11.0
Edit The technical team confirms the memory leak in NDSolve
and has forwarded an incident report to the developers.
This is not the first time the question in mentionned (cf in particular this recent question NDsolve memory leak), but there seems to be a serious issue of memory leak - or am I missing something?
First example (no leak) Let's loop 1000 times over the first example in the documentation of NDSolve
:
$HistoryLength = 0;
s := NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1},
y, {x, 0, 30}];
temp = MemoryInUse[];
Table[s, {i, 1000}];
MemoryInUse[] - temp
-1256
There is no significant increase in the memory usage.
Second example (memory leak?!) Now let's loop 1000 times with NDSolve
using another example from the same documentation. I see no programming difference in terms of memory, however this time the used memory increases significantly (and for other systems of equations, it can increase much faster).
s2 := NDSolve[{y''[x] + Sin[y[x]] y[x] == 0, y[0] == 1, y'[0] == 0}, y, {x, 0, 30}]
temp = MemoryInUse[];
Table[s2, {i, 1000}];
MemoryInUse[] - temp
293 696
Additionally, Remove[s2]
or Clear[s2]
does not free any memory (I think that's normal, but what is the memory used for?).
How come does the memory usage increases, and how to overcome this serious problem?
Tested on MMA 10.3.0.0 with Ubuntu 15.10 64 bits
Update (09 Aug 2016): I just installed version 11.0 and the leak is still present.
365528
as output for the first example and721896
- for the second. If I putClearSystemCache[]
afterTable
I get-1760
and294296
correspondingly. $\endgroup$ClearSystemCache
will reduce the memory usage only once if you are not testing with a fresh kernel :) $\endgroup$