| MATLAB® | ![]() |
| On this page… |
|---|
General Suggestions for Reclaiming Memory |
The MATLAB® software generates an Out of Memory message whenever it requests a segment of memory from the operating system that is larger than what is currently available. When you see the Out of Memory message, use any of the techniques discussed under Strategies for Efficient Use of Memory to help optimize the available memory. If the Out of Memory message still appears, you can try any of the following:
Compress data to reduce memory fragmentation.
If possible, break large matrices into several smaller matrices so that less memory is used at any one time.
If possible, reduce the size of your data.
Make sure that there are no external constraints on the memory accessible to MATLAB. (On The Open Group UNIX®[1] systems, use the limit command to check).
Increase the size of the swap file. We recommend that you configure your system with twice as much swap space as you have RAM. See Increasing System Swap Space, below.
Add more memory to the system.
The platforms and operating systems that MATLAB supports have different memory characteristics and limitations. In particular, the process limit is the maximum amount of virtual memory a single process (or application) can address. On 32-bit systems, this is the most important factor limiting data set size. The process limit must be large enough for MATLAB to store all of the data it is to process, plus M code, the MATLAB executable itself, and additional state information.
Where possible, choose an operating system that maximizes this number, that is, a 64-bit operating system. The following is a list of MATLAB supported operating systems and their process limits.
| Operating System | Process Limit |
|---|---|
| 32-bit Microsoft®Windows® XP, Windows Vista™. | 2 GB |
| 32-bit Windows XP with 3 GB boot.ini switch or 32-bit Windows Vista with increaseuserva set (see later) | 3 GB |
| 32-bit Linux® (Linux is a registered trademark of Linus Torvalds.) | ~3 GB |
| 64-bit Windows XP, Apple®Macintosh® OS X, Linux, or Sun™Solaris™ running 32-bit MATLAB | ≤ 4 GB |
| 64-bit Windows XP, Windows Vista, Linux, or Solaris running 64-bit MATLAB | 8 TB |
To verify the current process limit of MATLAB on Windows systems, use the memory function.
Maximum possible array: 583 MB (6.111e+008 bytes) * Memory available for all arrays: 1515 MB (1.588e+009 bytes) ** Memory used by MATLAB: 386 MB (4.050e+008 bytes) Physical Memory (RAM): 2014 MB (2.112e+009 bytes) * Limited by contiguous virtual address space available. ** Limited by virtual address space available.
When called with one output variable, the memory function returns or displays the following values. See the function reference for memory to find out how to use it with more than one output.
| memory Return Value | Description |
|---|---|
| MaxPossibleArrayBytes | Size of the largest single array MATLAB can currently create |
| MemAvailableAllArrays | Total size of the virtual address space available for data |
| MemUsedMATLAB | Total amount of memory used by the MATLAB process |
View the value against the Total entry in the Virtual Memory section. It is shown as 2 GB in the table, which is the default on Windows XP systems. On UNIX systems, see the ulimit command to view and set user limits including virtual memory.
You can increase the workspace size by approximately 150 MB (5-9 %) on 32-bit Windows XP systems if you start MATLAB without the Sun Java™ VM. To do this, use the command line option -nojvm to start MATLAB. This does not, however, increase the size of the largest contiguous block, and therefore largest matrix.
On Macintosh OS X, Solaris, and 32-bit Linux systems, the -nojvm option gives you approximately 400 MB more memory. It also increases the size of the largest contiguous block by about the same.
Using -nojvm comes with a penalty in that you will lose many features that rely on the Java software, including the entire development environment.
Starting MATLAB with the -nodesktop option does not save any substantial amount of memory.
Shutting down other applications and services (e.g., using msconfig on Windows systems) can help if total system memory is the limiting factor, but usually process limit (on 32-bit machines) is the main limiting factor.
The total memory available to applications on your computer is comprised of physical memory (RAM), plus a page file, or swap file, on disk. The page or swap file can be very large, even on 32-bit systems (e.g., 16 TB (terabytes) on 32-bit Windows, 512 TB on 64-bit Windows). The operating system allocates the virtual memory of each process to either physical RAM or to this file, depending on its needs and those of other processes.
How you set the swap space for your computer depends on what operating system you are running on.
For more information about swap space, type pstat -s at the UNIX command prompt. For detailed information on changing swap space, ask your system administrator.
You can change your swap space by using the mkswap and swapon commands. For more information on the above commands, type man followed by the command name at the Linux prompt.
Follow the steps shown here:
In the System Properties GUI, select the Advanced tab. In the section labeled Performance, click the Settings button.
In the Performance Options GUI, click the Advanced tab. In the section labeled Virtual Memory, click the Change button
In the Virtual Memory GUI, under Paging file size for selected drive, you can change the amount of virtual memory.
Microsoft Windows XP systems can allocate 3 GB (instead of the default 2 GB) to processes, if you set an appropriate switch in the boot.ini file of the system. The MathWorks recommends that you only do this with Windows XP SP2 systems or later. This gives an extra 1 GB of virtual memory to MATLAB, not contiguous with the rest of the memory. This enables you to store more data, but not larger arrays, as these are limited by contiguous space. This is mostly beneficial if you have enough RAM (e.g., 3 or 4 GB) to use it.
After setting the switch, confirm the new value of the virtual memory after restarting your computer and using the memory function.
[userview systemview] = memory;
systemview.VirtualAddressSpace
ans =
Available: 1.6727e+009 % Virtual memory available to MATLAB.
Total: 2.1474e+009 % Total virtual memory
For more documentation on this option, use the following URL:
http://support.microsoft.com/support/kb/articles/Q291/9/88.ASP
Similarly, on machines running Microsoft Windows Vista, you can achieve the same effect by using the command:
BCDEdit /set increaseuserva 3072
For more documentation on this option, use the following URL:
http://msdn2.microsoft.com/en-us/library/aa906211.aspx
There are no functions implemented to manipulate the way MATLAB handles Microsoft Windows system resources. Windows systems use these resources to track fonts, windows, and screen objects. Resources can be depleted by using multiple figure windows, multiple fonts, or several UI controls. One way to free up system resources is to close all inactive windows. Windows system icons still use resources.
[1] UNIX is a registered trademark of The Open Group in the United States and other countries.
![]() | Strategies for Efficient Use of Memory | Programming Tips | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |