Main Content

MATLAB Runtime Component Cache and Deployable Archive Embedding

For all deployment targets except for Java®, compiled application data is embedded directly in the deployable archive by default and extracted to a temporary folder at run time. This temporary folder is known as the MATLAB® Runtime component cache. When a compiled application runs, the files in the deployable archive (CTF file) are extracted to the MATLAB Runtime component cache. For details on data extraction with Java packages, see Define Embedding and Extraction Options for Deployable Java Archive.

Cache Size and Location

The default maximum cache size is 32 MB in releases prior to R2024b, or 1024 MB starting in R2024b. The default component cache location is listed in the following table.

PlatformBefore R2024bSince R2024b
Windows®%LOCALAPPDATA%\Temp\%USERNAME%\mcrCache<version>%LOCALAPPDATA%\MathWorks\MatlabRuntimeCache\<release_version>
Linux®$HOME/.mcrCache<version>$HOME/.MathWorks/MatlabRuntimeCache/<release_version>
Mac

A cache is not used in MATLAB R2020a and later. The app bundle contains the files necessary for run time.

Change Options Using Environment Variables

Using environment variables, you can specify the following options for the MATLAB Runtime component cache:

  • Define the default location where you want the deployable archive to be automatically extracted

  • Add diagnostic error printing options that can be used when automatically extracting the deployable archive, for troubleshooting purposes

  • Adjust the MATLAB Runtime component cache size for performance reasons

Use the following system environment variables to change these settings.

Environment VariablePurposeNotes
MCR_CACHE_ROOTWhen set to the location of where you want the deployable archive to be extracted, this variable overrides the default per-user component cache location. This is true for embedded .ctf files only.On macOS, this variable is ignored in MATLAB R2020a and later. The app bundle contains the files necessary for run time.
MCR_CACHE_SIZEWhen set, this variable overrides the default component cache size.The initial limit for this variable is 32M (megabytes), or 1024M starting in R2024b. This may, however, be changed after you have set the variable the first time. Edit the file .max_size, which resides in the file designated by running the mcrcachedir command, with the desired cache size limit.

Override Default Behavior

For targets besides Java, you can direct mcc to not embed the deployable archive in generated binaries using the mcc -C option. You can use this option to troubleshoot problems with the deployable archive, as the log and diagnostic messages are much more visible.

You can also implement this override by adding the -c flag in the Settings section of the compiler app.

If you are using a compiler.build function, use the EmbedArchive=false option.

Note

If you run mcc specifying conflicting wrapper and target types, the archive will not be embedded into the generated component, as if you had specified the -C option to mcc. For example:

mcc -W lib:myLib -T link:exe test.m test.c

Related Topics