Error Out of memory.

I had a "Out of memory. Type HELP MEMORY for your options"
I added 2 GB to my RAM so that according to the HELP MEMORY this would be enough to complete the script. However I now get the same error and HELP MEMORY states that I now need even more memory. The memory that it states I need is always just over what is available in RAM. I know I am doing something basically stupid here, but I do not know what.

Answers (2)

Jan
Jan on 23 Mar 2017
Please post any details: The relevant part of the code and the absolute size of the memory (adding 2 GB to a 64 GB machine will not be trustworthy).
You do not need only a certain amount of RAM, but for allocating large arrays, there must be a free contiguous block of memory available. If one byte is reserved in between for another variable, the memory is not available as block anymore. This is called "memory fragmentation" and it cannot be controlled directly. Use this for checking:
feature('memstats')
A missing pre-allocation can lead to a fragmentation of teh memory.

8 Comments

Lucy Gillis
Lucy Gillis on 23 Mar 2017
Edited: Jan on 23 Mar 2017
Hi thanks for your quick answer. I have both errors for not enough total memory and not enough continuous memory. I have de-fragmented my memory two weeks, ago but I should do this again. I now have 2.5 GB of memory, I added 1 GB and am running a 34-bit machine, old I know, but it the only thing I have which I can work with at the moment.
Here is where I think it runs out of memory (line 21)
disp('Reading available mass of sediment data....')
R.bodsed=vs_let_scaler(trim,'map-sed-series',{0}, ...
'BODSED', {0,0,0},'quiet');
disp ('Reading concentration data...')
Jan
Jan on 23 Mar 2017
The fragmentation of the memory means the RAM, not the hard-disk. Usually the RAM is fragmented in some milliseconds, while hard disks tend to take weeks for substantial fragmentations.
Please explain, what "trim" is. If it is a large system, most likely the final answer will be: This cannot be computed on a 32 bit machine.
Thanks. Trim is a structure file of size 8842 bytes. I did get the script to run on a 32 bit computer about 2 years ago. Although I did think that I had at that time 4GB of memory.
Jan
Jan on 23 Mar 2017
@Lucy: It does not matter how large the struct is, but its contents define the problem to solve. E.g. rand(1e6) is a small code, but produces a huge array. Currently we still cannot even guess, what kind of problem you try to solve. Perhaps it is a typo only like in rand(1e6) when rand(1, 1e6) is meant.
Rik
Rik on 23 Mar 2017
You may also use the step-by-step feature in the debugger to find out what is happening. That is usually the easiest way to spot errors like rand(1e6) instead of rand(1,1e6).
@Jan and @Rik thanks for the quick answer and apologies for my tardy one. I will go through my script and see if there is a type. The de-bugger states that I have two variables that are not used but are defined but that is all. I think my main confusion is that before I put it more memory matlab only stated I needed slightly more to do run the script but now after I have added more memory it states I need even more. The script is complicated but basically what I am doing is graphing the results from another mode. Big thanks everyone.
Rik
Rik on 24 Mar 2017
I meant using break points etc. You should be able to activate one by clicking next to the line number in the editor.
Hi Rik, thanks for the explanation. I have gone through the de-bugging but no issues found.

Sign in to comment.

Rik
Rik on 23 Mar 2017

0 votes

The list below is shamelessly copied from Jan Simon. Seeing as this some of these suggested solutions seem not to work, there are two options. You either need to offer more details about your code, or you need to try the other suggestions from this list.
  • Install more RAM
  • Care for a proper pre-allocation to reduce memory fragmentation
  • Install more RAM
  • Run a 64-bit version of Matlab
  • Install more RAM
  • Close other applications
  • Install more RAM
  • Use the smallest data type, which represents your data exactly, e.g. a single occupies 4 bytes instead of 8 for a double.
  • Install more RAM
  • Increase the virtual memory
  • But guess, if real RAM is better than virtual...
(If you are really, really desperate, you could consider converting your code to loops, but don't tell anyone I said that.)

1 Comment

Hi, thanks for your answer. I installed more RAM....the max I can. My computer is really fast now but I still get the out of memory error. Have already closed all other applications and increased the virtual memory and also de-fragmented the memory. Any other suggestions... thanks!

Sign in to comment.

Asked:

on 23 Mar 2017

Commented:

on 24 Mar 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!