I have written a code in Mathematica which creates as a result an array with 19280 arrays, each with 4 elements. The first three being numbers and the fourth being another array with 914 elements. It works, and the final array is stored in a .dat file 206.8 MB in size. The program says the maximum memory used should be approximately 3.2GB (using the command MaxMemoryUsed[]). However, when running the program, the used memory in the system goes up approximately 15GB. Also, after the program has finished and the notebook is closed, this memory usage remains. It is only after quitting the Kernel manually that the memory usage goes back to normal. The $HistoryLength is set to zero. The file is created by reading and writing it in the following Do loop:

datos = Evalvecmin[μ120, μ23i, μ23f, μ23step];
tmp = << "datos_Na2M25par_sepfino5.dat";
eminvecminq = Union[tmp, datos];
eminvecminq >> "datos_Na2M25par_sepfino5.dat" , {μ120, μ12i, μ12f, μ12step}]

And it’s in this step that the memory usage starts increasing way more than it should. Why is the memory usage going up so much? Thank you, Juan José

  • 1
    $\begingroup$ Sounds like a classical memory leak. It's not clear to me though what Evalvecmin and μ23i, μ23f, μ23step are. What happens if you 1.) remove the Union statement from the loop 2.) define datos only once outside the loop (such that Evalvecmin is called at most once)? If the memory leak persists, it should be a leak in Get or Put. Try also Import and Export with different file types. But the problem could lie in Evalvecmin as well. $\endgroup$ – Henrik Schumacher Mar 14 '18 at 8:33
  • $\begingroup$ @HenrikSchumacher. Thank you. I have tried your suggestions and it does not solve the problem. I contacted Wolfram Support and this was their answer: "I have run your code and do not see anything unexpected. The high memory use has to do with the way we store arrays of values. When we cannot create packed arrays the memory goes up 4 to 8 times larger because we have to store data types with each entry. You have made a number of global assignments in your code and have not cleared the values after running your code so putting the notebook away is not going to reduce the memory." $\endgroup$ – Juanjo Apr 27 '18 at 0:59

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.