Unable to clear mex file

조회 수: 16 (최근 30일)
Jim Hokanson
Jim Hokanson 2017년 2월 16일
댓글: Jim Hokanson 2017년 9월 15일
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:
clear('my_package.myMexFunction')
However, the mex code is relatively simple, with the only memory allocation being for the output:
plhs[0] = mxCreateLogicalMatrix(1,1);
mxLogical *pl = mxGetLogicals(plhs[0]);
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?
  댓글 수: 2
Walter Roberson
Walter Roberson 2017년 2월 21일
Is it possible that there is a lingering handle to the function in an object that belongs to the package?
Jim Hokanson
Jim Hokanson 2017년 4월 15일
Unfortunately I got distracted with other things and now I can't find the test case that I was using :/

댓글을 달려면 로그인하십시오.

채택된 답변

James Tursa
James Tursa 2017년 2월 21일
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
clear mymex
[M X] = inmem
% results for X no longer list mymex (i.e., it has been cleared)
  댓글 수: 1
Jim Hokanson
Jim Hokanson 2017년 9월 15일
I finally got back to writing some of this code and encountered this problem again (although apparently a different file since this one was not in a package). Clearing the mex file worked great. Strangely I only encountered this problem on Windows, not on Mac (although versions may be different).

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by