Display Memory Usage

Use the Status Bar

The amount of memory available on your computer can greatly affect your symbolic computations. First, some computations cannot run without enough memory. In this case, you get the "out of memory" error. Second, if the MuPAD® engine uses virtual memory by swapping data on and off the storage device, computations can run much slower than they run if the system does not use virtual memory. Observing memory usage when executing your code can help you understand whether your code uses available memory efficiently.

The simplest tool for observing the memory usage is the status bar. You can find the status bar at the bottom of a MuPAD notebook. If you do not see the status bar, select View > Status Bar. The far left end of the status bar displays the current engine state, including memory and time used during the most recent computations. While a computation is still running, the status bar information keeps changing.

If the engine is not connected to your notebook, the status bar displays Not Connected. For more information about the status bar, see Viewing Status Information.

    Note:   When you perform computations in several MuPAD notebooks, each notebook starts its own engine. In this case, watch for the total amount of memory used by all MuPAD engines (the mupkern.exe processes).

Generate Memory Usage Reports Periodically

When a computation takes a long time to run, it can be helpful to display progress information. In this case, MuPAD can issue periodic messages showing active memory usage, reserved memory, and evaluation time. You can control the frequency with which MuPAD prints such messages.

To set the frequency of these periodic messages, use the Pref::report function. By default, the value of Pref::report is 0; MuPAD does not print periodic status messages. If you increase the value to 1, MuPAD prints status messages approximately every hour. (The exact frequency depends on your machine.) The maximum value accepted by Pref::report is 9.

Suppose you want to generate and sort the list of 10,000,000 random integer numbers. These operations take a long time because of the huge number of elements. If you set the value of Pref::report to 4, MuPAD displays a few status messages while executing these operations:

sort([random() $ i = 1..10^7]):
 [used=167852k, reserved=168579k, seconds=30]
[used=294614k, reserved=295370k, seconds=60] [used=421376k, reserved=422161k,

If you increase the value of Pref::report to 6, MuPAD prints the status messages more frequently:

sort([random() $ i = 1..10^7]):
 [used=84035k, reserved=84661k, seconds=10]
[used=126987k, reserved=127664k, seconds=21] [used=169940k, reserved=170600k,
seconds=32] [used=212892k, reserved=213537k, seconds=43] [used=255844k,
reserved=256540k, seconds=54] [used=298797k, reserved=299476k, seconds=65]
[used=341749k, reserved=342413k, seconds=76] [used=384701k, reserved=385416k,
seconds=87] [used=427654k, reserved=428352k, seconds=98] [used=470606k,
reserved=471355k, seconds=109] 

Every time you execute this example, MuPAD adds a new list of 107 random numbers and stores that list in the history table. By default, the history table contains up to 20 elements. While this list remains in the history table, MuPAD cannot release the memory needed to store 107 integers. To release this memory, use one of these alternatives:

  • Continue computations waiting until MuPAD writes 20 new elements to the history table. Performing computations with a reduced amount of available memory can be very slow.

  • Terminate the MuPAD engine connected to the notebook by selecting Notebook > Disconnect. The new engine starts when you evaluate any command in the notebook.

  • Clear the history table by setting the value of variable HISTORY to 0. This variable specifies the maximum number of elements in the history table. To restore the default value of HISTORY, enter delete HISTORY:

delete HISTORY:

For more information about the history mechanism in MuPAD, see History Mechanism.

For further computations, also restore the default value of Pref::report:


Generate Memory Usage Reports for Procedure Calls

MuPAD can print memory usage information when you execute a procedure in the tracing mode. In this case, the system reports memory usage on each step of a procedure call.

For example, create the recursive procedure juggler that computes the Juggler number sequence for any initial positive integer n:

juggler := proc(n:Type::PosInt)
  J := append(J, n);
  if n = 1 then
  if testtype(n, Type::Even) then

Suppose you want to see the memory usage report for every call to this procedure. First call the prog::trace function with the Mem option. Then switch execution of the juggler procedure to the tracing mode:


Now when you call the juggler procedure, the tracing report shows the memory usage for each call to juggler:

J := []:
juggler(7) [mem: 5338408]   enter juggler(18) [mem: 5373600]     enter
juggler(4) [mem: 5374080]       enter juggler(2) [mem: 5374584]  
      enter juggler(1) [mem: 5375064]         computed [7, 18, 4,
2, 1] [mem: 5375032]       computed [7, 18, 4, 2, 1] [mem: 5374648]
    computed [7, 18, 4, 2, 1] [mem: 5374264]   computed [7, 18, 4,
2, 1] [mem: 5373880] computed [7, 18, 4, 2, 1] [mem: 5373524] 

The Mem option is independent of the traced procedure. Now if you use prog::trace to trace any other procedure, prog::trace displays memory usage in every step of that procedure. Remove this global option for further computations:

prog::trace(Mem = FALSE)

To stop tracing the juggler procedure, use the prog::untrace function:

Was this topic helpful?