Skip to Main Content Skip to Search
Product Documentation

About Memory Management and Cleanup

Overview

Generated C++ code provides consistent garbage collection via the object destructors and the MCR'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 MCR, it is created in the managed memory space of the MCR.

Therefore, it is very important that you never create mxArrays (or call any other MathWorks 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 Calling a Shared Library.

For more information about mxArray, see Use the mxArray API to Work with MATLAB Types.

  


Free MATLAB Compiler Interactive Kit

Learn how to build standalone executables and C/C++ shared libraries from MATLAB code.


Get free kit

Trials Available

Try the latest version of MATLAB Compiler.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS