Set a memory limit for the session

MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.




Pref::maxMem(kbytes) with kbytes greater than 0 sets a limit for the physically allocated memory of the current MuPAD® session. A computation exceeding this memory limit raises an error.

The physically allocated memory is the second of the values returned by bytes().


The memory limit is “soft” because the memory is checked only occasionally. Usually, more memory is actually used before the excess is detected. Cf. Example 1.

The call Pref::maxMem() returns the current value of the memory limit without changing it.

The call Pref::maxMem(NIL) switches off the memory watch dog.


Example 1

No computation should increase the memory usage of the current MuPAD session to more than a total of 10 megabytes:

Pref::maxMem(10 * unit::MByte):

The following loop creates larger and larger matrices until the memory limit is exceeded. Note that the current physical memory allocation returned by bytes()[2] is measured in bytes:

for n from 100 to 150 step 5 do
   A := linalg::vandermonde([x.j $ j=1..n]);
   print(n, ceil(bytes()[2]/1024)*unit::kByte);

 Error: Out of
memory [watchdog-memory];   Evaluating: linalg::vandermonde 
Error: Out of memory. [watchdog-memory]
  Evaluating: linalg::vandermonde

Note that the memory limit was exceeded when computing the 115 ×115 Vandermonde matrix. However, because the memory consumption is measured only occasionally, this matrix was generated successfully without an error. Only in the next step, the memory watchdog recognizes excessive memory usage and aborts the computation of the 120×120 Vandermonde matrix.

delete A:



The memory limit in kBytes: a nonnegative integer or an expression using unit::Byte, unit::kByte, unit::MByte, or unit::GByte.

Return Values

Previously defined memory limit: 0 or an expression involving unit::MByte.

See Also

MuPAD Functions