In MATLAB, clear mex
unloads all MEX-files from memory (unless they're locked). Under previous versions of macOS, I was able to re-compile a MEX-file and run the modified version without restarting MATLAB, simply by issuing a clear mex
command. This is no longer possible under Mojave.
For example, take this trivial MEX-file (get_data_pointer.c
):
#include "mex.h"
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
plhs[0] = mxCreateNumericMatrix(1, 1, mxUINT64_CLASS, mxREAL);
*(uint64_t*)mxGetData(plhs[0]) = (uint64_t)mxGetData(prhs[0]);
}
We can create the MEX-file and load it in memory with
mex get_data_pointer.c
get_data_pointer(0)
To clear it,
clear mex
[~,mexfiles] = inmem
version -modules
inmem
indeed returns an empty cell array indicating no MEX-files are loaded in memory, But version -modules
(undocumented, from this answer) still shows /Users/cris/matlab/get_data_pointer.mexmaci64
in its output. And changing the MEX-file source code and re-compiling demonstrates that, indeed, the MEX-file is never reloaded, the old version is still being run until one exits MATLAB.
I am seeing this on MATLAB R2017a on macOS Mojave. This was never a problem with the same MATLAB version under High Sierra.
How can I force MATLAB to unload the MEX-file without restarting?