| MATLAB® | ![]() |
| On this page… |
|---|
The following functions can help you to manage memory use while running the MATLAB software:
memory displays or returns information about how much memory is available and how much is used by MATLAB. This includes the following:
Size of the largest single array MATLAB can create at this time.
Total size of the virtual address space available for data.
Total amount of memory used by the MATLAB process for both libraries and data.
Available and total Virtual Memory for the MATLAB software process.
Available system memory, including both physical memory and paging file.
Available and the total physical memory (RAM) of the computer.
whos shows how much memory MATLAB currently has allocated for variables in the workspace.
pack saves existing variables to disk, and then reloads them contiguously. This reduces the chances of running into problems due to memory fragmentation.
clear removes variables from memory. One way to increase the amount of available memory is to periodically clear variables from memory that you no longer need.
If you use pack and there is still not enough free memory to proceed, you probably need to remove some of the variables you are no longer using from memory. Use clear to do this.
save selectively stores variables to the disk. This is a useful technique when you are working with large amounts of data. Save data to the disk periodically, and then use the clear function to remove the saved data from memory.
load reloads a data file saved with the save function.
quit exits MATLAB and returns all allocated memory to the system. This can be useful on The Open Group UNIX systems, which do not free up memory allocated to an application (e.g., MATLAB) until the application exits.
You can use the save and load functions in conjunction with the quit command to free memory by:
Saving any needed variables with the save function.
Quitting MATLAB to free all memory allocated to MATLAB.
Starting a new MATLAB session and loading the saved variables back into the clean MATLAB workspace.
The whos command can give you an idea of the memory used by MATLAB variables.
A = ones(10,10); whos Name Size Bytes Class Attributes A 10x10 800 double
Note that whos does not include information about
Memory used by MATLAB (e.g., Sun Java code and plots).
Memory used for most objects (e.g., time series, custom) .
Memory for variables not in the calling workspace .
Shared data copies (e.g., memory for B in >>B=A;) will still have bytes used listed against it even when it does not use any memory (see the "Be aware of the Function Argument Passing Model" section earlier).
![]() | Memory Allocation | Strategies for Efficient Use of Memory | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |