tags:

views:

4702

answers:

5

When I run a sample script in Matlab, it says:

Out of memory. Type HELP MEMORY for your options.

When I type "memory", it reports:

Maximum possible array:             156 MB (1.638e+008 bytes) *
Memory available for all arrays:    740 MB (7.756e+008 bytes) **
Memory used by MATLAB:             1054 MB (1.105e+009 bytes)
Physical Memory (RAM):             3070 MB (3.219e+009 bytes)

*  Limited by contiguous virtual address space available.
** Limited by virtual address space available.

Is there any way to get around this error? I'm using Windows XP x32 with Matlab 2009a.

+1  A: 

Interestingly enough, the MATLAB documentation has a page on resolving out of memory errors.

It didn't list a specific way to increase the max array size allotment, however.

Mark Rushakoff
+3  A: 

pack does a memory defragmentation, it might help you a bit as far as the contiguous memory available.

Marcin
Thanks for the comment. Appreciated!
Gravitas
+2  A: 

Remember, when MATLAB says it's out of memory, it means it's out of contiguous memory, so rebooting or restarting MATLAB may work.

But, I'd recommend optimizing your code and identifying how you're eating up so much memory. It could be an ill-designed recursive loop, or a bad indexing function (using doubles instead of logicals to index a huge matrix).

I practically lived with memory errors for a while since I was dealing with huge datasets, but there's always a workaround, ask specific questions and you'll be surprised.

Jacob
+1  A: 

What are you attempting to allocate when it runs out of memory? Do you have code to reproduce? A wide range of problems can cause out of memory errors.

To diagnose, use "dbstop if all error" to set a breakpoint on errors. The out of memory will trigger this, and you can use dbup, dbdown, and whos() to see what's consuming memory. Often an OOM is caused by a bad array size or index calculation, not just by big data structures. E.g. this will trigger an OOM in pretty much any 32-bit Matlab.

>> x = 1;
>> x(2^30) = 2
??? Out of memory. Type HELP MEMORY for your options.
Andrew Janke
Thanks for the comment. Appreciated! The problem is now fixed (see below).
Gravitas
+2  A: 

Problem fixed.

Under Windows XP x32, I managed to almost double the amount of memory available to Matlab by editing boot.ini to add the switch /3GB /USERVA=3030

[boot loader]
timeout=30
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect /3GB /USERVA=3030

Together with reducing our array sizes, this completely fixed the problem :)

I could have also fixed the problem by upgrading to Windows x64 or Windows 7 x64. This act also doubles the amount of memory available to Matlab, even if you stick with Matlab x32 and don't upgrade to Matlab x64. Windows x64 is just far more memory efficient, even with systems that only have 4GB of physical RAM installed.

Gravitas
"only have 4GB of physical RAM" -- heh, it's all relative
Jason S
Yes! When I was 16 year old, and the proud owner of an XT with 640KB of RAM, I would never have believed it if someone had said "Well, Shane, some day you'll say the following comment ..." :)
Gravitas

related questions