Display memory information

`memory`

userview = memory

[userview systemview] = memory

The

`memory`

function is available only on Microsoft^{®}Windows^{®}systems. Results are dependant on your computer hardware and the load on your computer.

`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:

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

function.

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 in the
Command Window. When you do assign the output, MATLAB returns
the information in a structure field. See the table below.

Command | Returned in |
---|---|

`memory` | Character vector labelled `Maximum possible array:` |

`user = memory` | Structure field `user.MaxPossibleArrayBytes` |

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

When you enter the `memory`

command without
specifying any outputs, MATLAB may also display one of the following
footnote on 64-bit systems:

`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 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 in the
Command Window. When you do assign the output, MATLAB returns
the information in a structure field. See the table below.

Command | Returned in |
---|---|

`memory` | Character vector labelled ```
Memory available for all
arrays:
``` |

`user = memory` | Structure field `user.MemAvailableAllArrays` |

When you enter the `memory`

command without
specifying any outputs, MATLAB may also display the following
footnote on 64-bit systems:

`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 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 in the
Command Window. When you do assign the output, MATLAB returns
the information in a structure field. See the table below.

Command | Returned in |
---|---|

`memory` | Character vector labelled `Memory used by MATLAB:` |

`user = memory` | Structure field `user.MemUsedMATLAB` |

Physical Memory is the available and total amounts of physical memory (RAM) on the computer running MATLAB.

When you enter the `memory`

command without
assigning its output, MATLAB displays the total memory in the
Command Window. When you do assign the output, MATLAB returns
both the available and total memory in a structure field. See the
table below.

Command | Value | Returned in |
---|---|---|

`memory` | Total memory | Character vector labelled `Physical Memory (RAM):` |

`[user,sys] = memory` | Available memory | Structure field `sys.PhysicalMemory.Available` |

Total memory | Structure field `sys.PhysicalMemory.Total` |

Available physical memory is the same as **Available** found
in the Windows Task Manager: Performance/Physical Memory, and
the total physical memory is the same as **Total**.

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

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`

.

Command | Return Value | Returned in Structure Field |
---|---|---|

`[user,sys] = memory` | Available memory | `sys.VirtualAddressSpace.Available` |

Total memory | `sys.VirtualAddressSpace.Total` |

You can monitor the difference:

VirtualAddressSpace.Total - VirtualAddressSpace.Available

as the Virtual Bytes counter in the Windows Performance
Monitor (e.g., Windows 7 Control Panel/Administrative Tools/Performance
Monitor). If you add a counter, the **Virtual Bytes** counter
is found under the **Process** menu. Select the counter,
and then select MATLAB from the **Instances of selected
object** pane.

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.

Command | Return Value | Returned in Structure Field |
---|---|---|

`[user,sys] = memory` | Available memory | `sys.SystemMemory` |

This is the same as the difference:

limit - total (in bytes)

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

Display memory statistics on a 64-bit Windows system:

memory

Maximum possible array: 14253 MB (1.495e+10 bytes) * Memory available for all arrays: 14253 MB (1.495e+10 bytes) * Memory used by MATLAB: 747 MB (7.833e+08 bytes) Physical Memory (RAM): 12279 MB (1.288e+10 bytes) * Limited by System Memory (physical + swap file) 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: 1.4957e+10 MemAvailableAllArrays: 1.4957e+10 MemUsedMATLAB: 784044032

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 = 1.4956e+10

```
% --- Memory available for data ---
user.MemAvailableAllArrays
```

ans = 1.4956e+10

```
% --- Memory used by MATLAB process ---
user.MemUsedMATLAB
```

ans = 784039936

```
% --- Virtual memory for MATLAB process ---
sys.VirtualAddressSpace
```

ans = Available: 8.7910e+12 Total: 8.7961e+12

```
% --- Physical memory and paging file ---
sys.SystemMemory
```

ans = Available: 1.4956e+10

```
% --- Computer's physical memory ---
sys.PhysicalMemory
```

ans = Available: 2.7093e+09 Total: 1.2876e+10

Was this topic helpful?