MATLAB no longer unloading MEX-files after upgrade to macOS Mojave : <p>In MATLAB, <code>clear mex</code> 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 <code>clear mex</code> command. This is no longer possible under Mojave.</p>

<p>For example, take this trivial MEX-file (<code>get_data_pointer.c</code>):</p>

<pre class="lang-c prettyprint-override"><code>#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]);
}
</code></pre>

<p>We can create the MEX-file and load it in memory with</p>

<pre class="lang-matlab prettyprint-override"><code>mex get_data_pointer.c
get_data_pointer(0)
</code></pre>

<p>To clear it,</p>

<pre class="lang-matlab prettyprint-override"><code>clear mex
[~,mexfiles] = inmem
version -modules
</code></pre>

<p><code>inmem</code> indeed returns an empty cell array indicating no MEX-files are loaded in memory, But <code>version -modules</code> (undocumented, from <a href="https://stackoverflow.com/a/20407568/7328782">this answer</a>) still shows <code>/Users/cris/matlab/get_data_pointer.mexmaci64</code> 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.</p>

<p>I am seeing this on MATLAB R2017a on macOS Mojave. This was never a problem with the same MATLAB version under High Sierra.</p>

<p>How can I force MATLAB to unload the MEX-file without restarting?</p>
