| MATLAB Application Program Interface | Search  Help Desk |
| mexAtExit | Examples See Also |
Register a function to be called when the MEX-file is cleared or when MATLAB terminates
C Syntax
#include "mex.h" int mexAtExit(void (*ExitFcn)(void));
Arguments
ExitFcnReturns
Always returns 0.Description
UsemexAtExit to register a C function to be called just before the MEX-file is cleared or MATLAB is terminated. mexAtExit gives your MEX-file a chance to perform tasks such as freeing persistent memory and closing files. Typically, the named ExitFcn performs tasks like closing streams or sockets.
Each MEX-file can register only one active exit function at a time. If you call mexAtExit more than once, MATLAB uses the ExitFcn from the more recent mexAtExit call as the exit function.
If a MEX-file is locked, all attempts to clear the MEX-file will fail. Consequently, if a user attempts to clear a locked MEX-file, MATLAB does not call the ExitFcn.
Example
Seemexatexit.c in the mex subdirectory of the examples directory.
See Also
mexLock, mexUnlock