Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Memory Management and Cleanup

Overview

Generated C++ code provides consistent garbage collection via the object destructors and the MATLAB® Runtime's internal memory manager optimizes to avoid heap fragmentation.

If memory constraints are still present on your system, try preallocating arrays in MATLAB. This will reduce the number of calls to the memory manager, and the degree to which the heap fragments.

Passing mxArrays to Shared Libraries

When an mxArray is created in an application which uses the MATLAB Runtime, it is created in the managed memory space of the MATLAB Runtime.

Therefore, it is very important that you never create mxArrays (or call any other MATLAB function) before calling mclInitializeApplication.

It is safe to call mxDestroyArray when you no longer need a particular mxArray in your code, even when the input has been assigned to a persistent or global variable in MATLAB. MATLAB uses reference counting to ensure that when mxDestroyArray is called, if another reference to the underlying data still exists, the memory will not be freed. Even if the underlying memory is not freed, the mxArray passed to mxDestroyArray will no longer be valid.

For more information about mclInitializeApplication and mclTerminateApplication, see Call a Shared Library.

For more information about mxArray, see C Matrix Library API (MATLAB).

Was this topic helpful?