This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

mexMakeMemoryPersistent (C and Fortran)

Make memory allocated by MATLAB software persist after MEX-function completes

C Syntax

#include "mex.h"
void mexMakeMemoryPersistent(void *ptr);

Fortran Syntax

#include "fintrf.h"
subroutine mexMakeMemoryPersistent(ptr)
mwPointer ptr



Pointer to the beginning of memory allocated by one of the MATLAB® memory allocation routines


By default, memory allocated by MATLAB is nonpersistent, so it is freed automatically when the MEX function finishes. If you want the memory to persist, call mexMakeMemoryPersistent.


If you create persistent memory, you are responsible for freeing it when the MEX function is cleared. If you do not free the memory, MATLAB leaks memory. To free memory, use mxFree. See mexAtExit to see how to register a function that gets called when the MEX function is cleared. See mexLock to see how to lock your MEX function so that it is never cleared.

Introduced before R2006a