External Interfaces Reference Previous page   Next Page
mexAtExit

Register function to be called when MEX-function cleared or MATLAB terminates

C Syntax

Arguments

ExitFcn
   Pointer to function you want to run on exit.

Returns

Always returns 0.

Description

Use mexAtExit to register a C function to be called just before the MEX-function is cleared or MATLAB is terminated. mexAtExit gives your MEX-function 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-function 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-function 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.

Examples

See mexatexit.c in the mex subdirectory of the examples directory.

See Also

mexLock, mexUnlock


Previous page  mexAddFlops (Obsolete) mexCallMATLAB Next page

© 1994-2005 The MathWorks, Inc.