4
$\begingroup$

Every time I run NDsolve it uses some memory that I am not able to free later.

The following is an example code based on the spring equation (Hooke's law) that increases memory usage by 280 bytes each iteration.


$HistoryLength = 0;
tlimit = 1;
x0 = 1;
m = 1;
k = 1;

Do[
  memory1 = MemoryInUse[];
  Print[memory1];
  sol = NDSolve[{x''[t] == -k/m*x[t], x[0] == x0, x'[0] == 0}, x, {t, 0., tlimit}];
  Clear[sol];
  ClearSystemCache[];
  memory2 = MemoryInUse[];
  Print[memory2];
 , {x0, {0, 1, 2, 3}}]

memory2 - memory1

As you can see I have already tried with $HistoryLenght = 0, ClearSystemCache[], Clear[sol]

Does anyone know how to free that memory again so that the memory usage will not increase at every iteration?

$\endgroup$
  • $\begingroup$ Just asked a related question, if not duplicate, but with two MWE with different outcomes: mathematica.stackexchange.com/questions/116401/…. $\endgroup$ – anderstood Jun 27 '16 at 21:14
  • $\begingroup$ Thank you for letting me know! Hope someone can shed some light into it. $\endgroup$ – Mike B. Jun 27 '16 at 22:50
  • 1
    $\begingroup$ I was quite surprised you did not have any answer. I plan to give a bounty if I don't have an answer within two days. Here the correct link to the question: mathematica.stackexchange.com/questions/119501/… $\endgroup$ – anderstood Jun 27 '16 at 23:43
  • $\begingroup$ Mike, you should report that to WRI. $\endgroup$ – user21 Jun 28 '16 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.