While trying to compute a large number of Smith decompositions in Mathematica 11.0 under Windows 10, my computer keeps running out of memory for no apparent reason.

Here is a self-contained example illustrating the problem.

Define a 176-by-386 matrix A as follows (it seems that the matrix has to be sufficiently complicated for the problems to arise):

entry[i_, j_] := If[Length[Complement[j, i]] == 1, (-1)^Position[j, Complement[j, i][[1]]][[1,1]], 0]
A = Table[entry[i, j], {i, Subsets[Range[10], 3]}, {j, Subsets[Range[10], 4]}];

Now, we try to compute the SmithDecomposition of this matrix 10000 times in a row. We are not displaying any output or storing the result anywhere and the matrix we are computing with is fixed:

For[k = 1, k <= 10000, k++, SmithDecomposition[A];]

Despite this, each iteration of the For loop seems to be eating more and more memory and I can find no way to clear this memory up between iterations. (I tried using ClearSystemCache, setting $HistoryLength = 1, etc. as suggested in the answers to some related questions, but nothing seems to work.) The memory does not clear up after aborting the computation either.

What is eating up all my memory and how do I clear it up between successive computations?

Added: As noted by Henrik Schumacher in the comment, this problem does not seem to be present in Mathematica 11.3. I am still curious how to clear up memory after a leak of this kind. (When working on a computer that only has an earlier version of Mathematica available, this kind of error can be detrimental to work progress, so it would be nice to have a workaround.)

Is killing the kernel the only way or are there less drastic solutions?

  • 1
    $\begingroup$ I cannot reproduce that with version 11.3 on macOS. But that does not mean much since such issues can easily OS-dependent. $\endgroup$ – Henrik Schumacher Jan 26 '19 at 19:49
  • 1
    $\begingroup$ @HenrikSchumacher: I installed version 11.3 now and I cannot reproduce the problem in that version either. Must be a bug that they removed between these versions. $\endgroup$ – Dejan Govc Jan 26 '19 at 20:59
  • $\begingroup$ That's good to hear, Dejan! $\endgroup$ – Henrik Schumacher Jan 26 '19 at 21:02
  • $\begingroup$ @DejanGovc What version of Mathematica were you seeing the leak? $\endgroup$ – Chip Hurst Jan 28 '19 at 14:06
  • $\begingroup$ @ChipHurst: $\endgroup$ – Dejan Govc Jan 28 '19 at 14:08

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.