Consolidate workspace memory
pack reorganizes workspace data to maximize the size of the largest
contiguous free memory block. It consolidates fragmented memory by:
Saving all variables in the base and function workspaces to a temporary file
Clearing all variables and functions from memory
Reloading the base and function workspace variables back from the temporary file and then deleting the file
When MATLAB® runs out of memory on a 32-bit system,
find you some free memory without forcing you to delete variables. On a 64-bit system,
you do not need to use
pack. For more information about strategies
for reducing memory usage, see Strategies for Efficient Use of Memory
and Resolve “Out of Memory” Errors.
pack frees space in memory,
temporarily storing workspace data in a file specified by
Consolidate memory by running
pack in a
Change the current folder to the temporary folder for the system, run
pack, and then return to the previous folder.
cwd = pwd; cd(tempdir) pack cd(cwd)
filename— Name of file
Name of file, specified as a character vector or string scalar. The file must be in
a folder for which you have write permission. If you do not specify
pack temporarily stores your
workspace data in a file in your temporary folder.
When using the command form of
pack, you do not need to enclose
the input in single quotes. However, if
filename contains a space,
you must enclose the argument in single quotes; for example,
Do not use command form when
filename is a string. Use function
pack function is supported only in the Command Window. You
cannot call it from a function or script.
If the workspace contains a variable larger than 2 GB,
cannot save and reload your data.
pack function does not affect the amount of memory allocated
to the MATLAB process. You must end your MATLAB session to free up this memory.
pack function initializes all persistent variables to an
empty matrix (
). To maintain the value of persistent variables when
mlock in the functions in which they are declared.
Do not use the
pack function with objects that define events and
pack causes the destruction of any listeners defined for
the objects in the workspace. For information about restoring listeners when saving
objects, see Restore Listeners.