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.
365528as output for the first example and721896- for the second. If I putClearSystemCache[]afterTableI get-1760and294296correspondingly. – Alexey Popkov Jun 28 '16 at 03:51ClearSystemCachewill reduce the memory usage only once if you are not testing with a fresh kernel :) – xzczd Jun 28 '16 at 04:02ClearSystemCache[]I get2673480after the first run and then-1760for every further run. – Alexey Popkov Jun 28 '16 at 04:0594352except for the first run. @anderstood have you reported this to WRI? – xzczd Jun 28 '16 at 04:09s2a thousand times? – user21 Jun 28 '16 at 17:16NDSolve, so I need to use it a few thousand times, but because of the memory leak it overflows every 200 iterations. I hope this gives you enough insight on my need :-) – anderstood Jun 28 '16 at 18:07ParametricNDSolvecan help you? – user21 Jun 28 '16 at 18:13NDSolve. However, I triedParametricNDSolvewith a dummy parameter (s2 := ParametricNDSolve[{y''[x] + Sin[y[x]] y[x] == 0, y[0] == 1, y'[0] == 0}, y, {x, 0, 30}, {a}]), but it also suffers memory leak... – anderstood Jun 28 '16 at 20:30