# Clean memory after calculation [duplicate]

I make numerical calculation series with integrals in each term (Mathematica 11.1, system Linux Mint 18). I use ParallelSum with 4 kernels. I start $HistoryLength = 0 at the beginning. MemoryUsed[] at the beginning shows around 76Mb. After calculations it is around 100Mb but memory used in computer is all of my memory 7.5Gb from 8Gb. System monitor shows that there are 4 kernels with 1.2Gb each and 1 kernel with 140Mb and Mathematica itself 220Mb. How enforce Mathematica to clean kernels after calculations? • Are you setting $HistoryLength on the kernels? Some example code that reproduces the issue would help; make it take up less memory but still show the memory is not released. Dec 15, 2017 at 16:46
• @Edmund I do not know how to use HistoryLength on each kernel. I simply write $HistoryLength = 0 before calculations. When I start calculation I use ParallelSum and for this reason 4 my kernel loaded. – nail Dec 15, 2017 at 19:44 • @Edmund The code is following:$HistoryLength = 0; nn = {}; St = 5 10^3; For[k = 1, k <= 46, k++, pp0[k] = F1tmgr[1 + (k - 1) 2/10, d, n, 10, 1, St]; ps = pp0[k]; Print["k=", k, " ", "pp0[", k, "]=", pp0[k]]; For[i = 1, i < 100, i++, pp[i] = F1tmgr[1 + (k - 1) 2/10, d, n, 10, 1 + i St, (i + 1) St]; ps = ps + pp[i]; Print["i=", i, " ", "pp[", i, "]=", pp[i], " ", "ps=", ps]; If[Abs[pp[i]] < 10^-8, i = 100, i]]; AppendTo[nn, {1 + (k - 1) 2/10, ps}] && Put[nn, "tmS.txt"]]
– nail
Dec 15, 2017 at 19:46
• This answer has details on how to $HistoryLength = 0 on all kernels (156054). Dec 15, 2017 at 21:08 • Thank you. It really works. I use combination: CloseKernels[]; LaunchKernels[]; ParallelEvaluate[$HistoryLength = 0]; at the beginning of calculation. It cleans memory before new calculation.
– nail
Dec 16, 2017 at 17:41