Documentation Center

  • Trial Software
  • Product Updates

memory

Display memory information

Syntax

memory
userview = memory
[userview systemview] = memory

Limitations

  • The memory function is available only on Microsoft® Windows® systems. Results are dependant on your computer hardware and the load on your computer.

Description

memory displays information showing how much memory is available and how much the MATLAB® software is currently using. The information displayed at your computer screen includes the following items, each of which is described in a section below:

userview = memory returns user-focused information on memory use in structure userview. The information returned in userview includes the following items, each of which is described in a section below:

[userview systemview] = memory returns both user- and system-focused information on memory use in structures userview and systemview, respectively. The userview structure is described in the command syntax above. The information returned in systemview includes the following items, each of which is described in a section below:

Output Arguments

Each of the sections below describes a value that is displayed or returned by the memory function.

Maximum Possible Array

Maximum Possible Array is the size of the largest contiguous free memory block. As such, it is an upper bound on the largest single array MATLAB can create at this time.

MATLAB derives this number from the smaller of the following two values:

  • The largest contiguous memory block found in the MATLAB virtual address space

  • The total available system memory

To see how many array elements this number represents, divide by the number of bytes in the array class. For example, for a double array, divide by 8. The actual number of elements MATLAB can create is always fewer than this number.

When you enter the memory command without assigning its output, MATLAB displays this information as a string. When you do assign the output, MATLAB returns the information in a structure field. See the table below.

CommandReturned in
memoryString labelled Maximum possible array:
user = memoryStructure field user.MaxPossibleArrayBytes

All values are double-precision and in units of bytes.

Footnotes

When you enter the memory command without specifying any outputs, MATLAB may also display one of the following footnotes. 32-bit systems show either the first or second footnote; 64-bit systems show only the second footnote:

Limited by contiguous virtual address space available.

There is sufficient system memory to allow mapping of all virtual addresses in the largest available block of the MATLAB process. The maximum amount of total MATLAB virtual address space is either 2 GB or 3 GB, depending on whether the /3GB switch is in effect or not.

Limited by System Memory (physical + swap file) available.

There is insufficient system memory to allow mapping of all virtual addresses in the largest available block of the MATLAB process.

Memory Available for All Arrays

Memory Available for All Arrays is the total amount of memory available to hold data. The amount of memory available is guaranteed to be at least as large as this field.

MATLAB derives this number from the smaller of the following two values:

  • The total available MATLAB virtual address space

  • The total available system memory

When you enter the memory command without assigning its output, MATLAB displays this information as a string. When you do assign the output, MATLAB returns the information in a structure field. See the table below.

CommandReturned in
memoryString labelled Memory available for all arrays:
user = memoryStructure field user.MemAvailableAllArrays

Footnotes

When you enter the memory command without specifying any outputs, MATLAB may also display one of the following footnotes. 32-bit systems show either the first or second footnote; 64-bit systems show only the latter footnote:

Limited by virtual address space available.

There is sufficient system memory to allow mapping of all available virtual addresses in the MATLAB process virtual address space to system memory. The maximum amount of total MATLAB virtual address space is either 2 GB or 3 GB, depending on whether the /3GB switch is in effect or not.

Limited by System Memory (physical + swap file) available.

There is insufficient system memory to allow mapping of all available virtual addresses in the MATLAB process.

Memory Used By MATLAB

Memory Used By MATLAB is the total amount of system memory reserved for the MATLAB process. It is the sum of the physical memory and potential swap file usage.

When you enter the memory command without assigning its output, MATLAB displays this information as a string. When you do assign the output, MATLAB returns the information in a structure field. See the table below.

CommandReturned in
memoryString labelled Memory used by MATLAB:
user = memoryStructure field user.MemUsedMATLAB

Total Physical Memory (RAM)

Physical Memory (RAM) is the total physical memory (or RAM) in the computer.

When you enter the memory command without assigning its output, MATLAB displays this information as a string. See the table below.

CommandReturned in
memoryString labelled Physical Memory (RAM):

Virtual Address Space

Virtual Address Space is the amount of available and total virtual memory for the MATLAB process. MATLAB returns the information in two fields of the return structure: Available and Total.

CommandReturn ValueReturned in Structure Field
[user,sys] = memoryAvailable memorysys.VirtualAddressSpace.Available
Total memorysys.VirtualAddressSpace.Total

You can monitor the difference:

VirtualAddressSpace.Total - VirtualAddressSpace.Available

as the Virtual Bytes counter in the WindowsPerformance program. (e.g., Windows XP Control Panel/Administrative Tool/Performance program).

System Memory

System Memory is the amount of available system memory on your computer system. This number includes the amount of available physical memory and the amount of available swap file space on the computer running MATLAB. MATLAB returns the information in the SystemMemory field of the return structure.

CommandReturn ValueReturned in Structure Field
[user,sys] = memoryAvailable memorysys.SystemMemory

This is the same as the difference:

limit - total (in bytes)

found in the Windows Task Manager: Performance/Commit Charge.

Physical Memory

Physical Memory is the available and total amounts of physical memory (RAM) on the computer running MATLAB. MATLAB returns the information in two fields of the return structure: Available and Total.

CommandValueReturned in Structure Field
[user,sys] = memoryAvailable memorysys.PhysicalMemory.Available
Total memorysys.PhysicalMemory.Total

Available physical memory is the same as:

Available (in bytes)

found in the Windows Task Manager: Performance/Physical Memory

The total physical memory is the same as

Total (in bytes)

found in the Windows Task Manager: Performance/Physical Memory

You can use the amount of available physical memory as a measure of how much data you can access quickly.

Examples

Display memory statistics on a 32-bit Windows system:

memory

Maximum possible array:           677 MB (7.101e+008 bytes) *
Memory available for all arrays: 1601 MB (1.679e+009 bytes) **
Memory used by MATLAB:            446 MB (4.681e+008 bytes)
Physical Memory (RAM):           3327 MB (3.489e+009 bytes)

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

Return in the structure userview, information on the largest array MATLAB can create at this time, how much memory is available to hold data, and the amount of memory currently being used by your MATLAB process:

userview = memory

userview = 
   MaxPossibleArrayBytes: 710127616
   MemAvailableAllArrays: 1.6792e+009
           MemUsedMATLAB: 468127744

Assign the output to two structures, user and sys, to obtain the information shown here:

[user sys] = memory;

%  --- Largest array MATLAB can create ---
user.MaxPossibleArrayBytes
ans =
   710127616

%  --- Memory available for data ---
user.MemAvailableAllArrays
ans =
   1.6797e+009

%  --- Memory used by MATLAB process ---
user.MemUsedMATLAB
ans =
   467603456

%  --- Virtual memory for MATLAB process ---
sys.VirtualAddressSpace
ans = 
   Available: 1.6797e+009
       Total: 2.1474e+009

%  --- Physical memory and paging file ---
sys.SystemMemory
ans = 
   Available: 4.4775e+009

%   --- Computer's physical memory ---
sys.PhysicalMemory
ans = 
   Available: 2.3941e+009
       Total: 3.4889e+009

More About

expand all

Tips

Details on Memory Used By MATLAB

MATLAB computes the value for Memory Used By MATLAB by walking the MATLAB process memory structures and summing all the sections that have physical storage allocated in memory or in the paging file on disk.

Using the Windows Task Manager, you have for the MATLAB.exe image:

Mem Usage < MemUsedMATLAB < Mem Usage + VM Size (in bytes)

where both of the following are true:

  • Mem Usage is the working set size in kilobytes.

  • VM Size is the page file usage, or private bytes, in kilobytes.

The working set size is the portion of the MATLAB virtual address space that is currently resident in RAM and can be referenced without a memory page fault. The page file usage gives the portion of the MATLAB virtual address space that requires a backup that doesn't already exist. Another name for page file usage is private bytes. It includes all MATLAB variables and workspaces. Since some of the pages in the page file may also be part of the working set, this sum is an overestimate of MemUseMATLAB. Note that there are virtual pages in the MATLAB process space that already have a backup. For example, code loaded from EXEs and DLLs and memory-mapped files. If any part of those files is in memory when the memory builtin is called, that memory will be counted as part of MemUsedMATLAB.

Reserved Addresses

Reserved addresses are addresses sets aside in the process virtual address space for some specific future use. These reserved addresses reduce the size of MemAvailableAllArrays and can reduce the size of the current or future value of MaxPossibleArrayBytes.

Example 1 — Java Virtual Machine (JVM)

At MATLAB startup, part of the MATLAB virtual address space is reserved by the Java Virtual Machine (JVM) and cannot be used for storing MATLAB arrays.

Example 2 — Standard Windows Heap Manager

MATLAB, by default, uses the standard Windows heap manager except for a set of small preselected allocation sizes. One characteristic of this heap manager is that its behavior depends upon whether the requested allocation is less than or greater than the fixed number of 524,280 bytes. For, example, if you create a sequence of MATLAB arrays, each less than 524,280 bytes, and then clear them all, the MemUsedMATLAB value before and after shows little change, and the MemAvailableAllArrays value is now smaller by the total space allocated.

The result is that, instead of globally freeing the extra memory, the memory becomes reserved. It can only be reused for arrays less than 524,280 bytes. You cannot reclaim this memory for a larger array except by restarting MATLAB.

See Also

| | | | | | |

Tutorials

Was this topic helpful?