Unable to clear mex file
26 views (last 30 days)
Show older comments
Jim Hokanson on 16 Feb 2017
Commented: Jim Hokanson on 15 Sep 2017
I'm compiling a mex file and then moving it up a directory so that it is in the Matlab path. The movefile command fails with the error message: "The process cannot access the file because it is being used by another process."
The mex file is located in a package, so before calling the movefile command, I call:
This however doesn't fix the problem. TMW suggests that it may be a memory leak: https://www.mathworks.com/matlabcentral/answers/100577-why-am-i-unable-to-delete-mex-functions-from-memory-using-the-clear-mex-command
However, the mex code is relatively simple, with the only memory allocation being for the output:
plhs = mxCreateLogicalMatrix(1,1);
mxLogical *pl = mxGetLogicals(plhs);
I don't free anything in the mex file.
Running 'clear all' fixes the problem and lets me move the file. Is there an alternative?
James Tursa on 21 Feb 2017
I hadn't seen that TMW post about memory leaks and clearing mex routines. Not sure what the issue is there and what the other "process" is.
What is the actual name of your mex function file? Can you clear that name directly? E.g.,
% some code here to call a mex routine named "mymex.mexw32"
[M X] = inmem
% results for X list mymex
[M X] = inmem
% results for X no longer list mymex (i.e., it has been cleared)
More Answers (0)
Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!