# Out of Memory Error

I am currently constructing matrices, but I'm having problems with memory. When I evaluate some cells, the kernel quits due to lack of memory. I tried ClearSystemCache, Clear["Global'*"], and used MemoryInUse[] to check how much memory was freed, but not it was not enough.

When I use both clear functions and do a MemoryInUse[] from the top of my notebook, I get 38 441 336, which doesn't seem right considering I haven't started any computation. I would like to be able to clear as much memory as possible to continue with other calculations. Thank you.

Edit: I am working with 100x100x100x100 matrices since my goal is to do a ListVectorPlot with them. I tried SetPrecision[x, 1] for each element in the matrix, but it still doesn't work. I also tried with smaller matrices, like 25x25x25x25, still nothing. $HistoryLength=0 as well as Quit[] frees some memory but not enough. Here is my code for producing this large matrix which I get data from a file: (*vector plot of expectation values for positive psi *) expectvect = Import["Greens_Expectation.m", "Table"]; momentum = Import["Greens_Momentum.m", "Table"]; vectorplot = {}; i = 1; m = 1; n = 1; kx = -Pi; ky = -Pi; For[m = 1, i <= l^2*3, i += 3, tempvect = {{SetPrecision[ Evaluate[Sequence @@ ToExpression[momentum[[i]]]], 1], SetPrecision[ Evaluate[Sequence @@ ToExpression[momentum[[i + 1]]]], 1]}, {SetPrecision[ Evaluate[ Sequence @@ ToExpression[expectvect[[i]]]], 1], SetPrecision[ Evaluate[ Sequence @@ ToExpression[expectvect[[i + 1]]]], 1]}}; vectorplot = Join[ vectorplot, {tempvect}]; (*Print[vectorplot]*) ] ListVectorPlot[vectorplot]  • What was the input that caused the kernel to quit? It is normal for a small amount of memory, such as 38 MB, to be used after startup. – ilian Jun 10 '15 at 4:23 • Try$HistoryLength=0. – Sjoerd C. de Vries Jun 10 '15 at 5:58
• Very difficult to answer without code to reproduce. Apart from heeding @SjoerdC.deVries´ advice and starting with a new kernel, there is not a lot to be done without more information. – Yves Klett Jun 10 '15 at 10:53
• In this case, MaxMemoryUsed and MemoryConstraint may be your friend in tracking down the location of the issue. You may have an intermediate symbolic result that is blowing out your memory footprint. – Mark Kotanchek Jun 10 '15 at 14:28
• What do you get running DeveloperPackedArrayQ[] on either expectvect or momentum`? If it returns false, then a 100x100x100x100 matrix that is unpacked can easily take up a lot of space. – dr.blochwave Jun 10 '15 at 16:00