Programming and Data Types    

Platform-Specific Memory Topics

This section presents information specific to the Windows and UNIX platforms that may be helpful in conserving memory.

Windows Topics

The following topics apply to how the Microsoft Windows operating system handles memory.

Freeing Up System Resources.   There are no functions implemented to manipulate the way MATLAB handles Microsoft Windows system resources. Windows uses system resources to track fonts, windows, and screen objects. Resources can be depleted by using multiple figure windows, multiple fonts, or several UIcontrols. One way to free up system resources is to close all inactive windows. Iconified windows still use resources.

UNIX Topics

The following topics apply to how the UNIX operating system handles memory.

Freeing Cleared Memory on UNIX.   On UNIX systems, MATLAB does not return memory to the operating system even after variables have been cleared. This is due to the manner in which UNIX manages memory. UNIX does not accept memory back from a program until the program has terminated. So, the amount of memory used in a MATLAB session is not returned to the operating system until you exit MATLAB.

To free up the memory used in your MATLAB session, save your workspace variables, exit MATLAB, and then load your variables back in.

Additional Memory Used to Execute External Commands.   On UNIX systems, you may get Out of Memory errors when executing an operating system command from within MATLAB (using the shell escape (!) operator). This is because, when a process shells out to a subprocess, UNIX allocates as much memory for the subprocess as has been allocated for the parent process.

For example, if your MATLAB session occupies 5 Mbytes of memory, if you shell out, the operating system must allocate another 5 Mbytes.

Reusing Heap Memory.   MATLAB requests memory from the operating system when there is not enough memory available in the MATLAB heap to store the current variables. It reuses memory in the heap as long as the size of the memory segment required is available in the MATLAB heap.

For example, on one machine these statements use approximately 15.4 MB of RAM:

This statement uses approximately 16.4 MB of RAM:

These statements use approximately 32.4 MB of RAM. This is because MATLAB is not able to fit a 2.1 MB array in the space previously occupied by two 1-MB arrays.

The simplest way to prevent overallocation of memory, is to allocate the largest vectors first. These statements use only about 16.4 MB of RAM

  "Out of Memory" Errors MATLAB Programming Tips