MATLAB Answers

clear MEX not unloading DLLs in 2016b

조회 수: 30(최근 30일)
Andrew Cunningham
Andrew Cunningham 2018년 8월 1일
댓글: Andrew Cunningham 2018년 8월 7일
Neither "clear all" or "clear mex" is unloading MEX DLLs. I can verify this by attaching to Matlab in the Visual C++ debugger and looking for DLL "unloading/loading" happening.
This has been asked before, with the following "answer" https://www.mathworks.com/matlabcentral/answers/100577-why-am-i-unable-to-delete-mex-functions-from-memory-using-the-clear-mex-command
It is unclear in this answer what is mean by memory leaks preventing MEX unloading? A MEX function , might have ,for example, have static C++ objects that allocate memory. That will only be de-allocated when the DLL is unloaded.
I remember in a previous version of Matlab , "clear MEX" would force all MEX DLL's to be unloaded.
  댓글 수: 2
Andrew Cunningham
Andrew Cunningham 2018년 8월 1일
These are our custom MEX DLLs that are a thin layer over other application specific DLLs. I am just trying to understand the restrictions/rules on unloading. Way back in Matlab 2007b, "clear mex" would definitely unload the DLLs. Now it doesn't.

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

답변(1개)

Philip Borghesani
Philip Borghesani 2018년 8월 2일
편집: Philip Borghesani 2018년 8월 2일
Clear mex and clear all should still unload mex files that are not in use or locked (see mexLock ). The referenced answer is a bit vague, classic memory leaks will not prevent a mex file from unloading but some resource leaks might.
It is possible for back references or other OS activity to keep a mex file loaded even if MATLAB has attempted to unload it. Sometimes the OS or an antivirus will keep a dll locked for a period of time after MATLAB unloads it.
Check using inmem to see if MATLAB still has it locked. Process Explore (procexp.exe) can find if other applications have a dll locked.
You can also try using m mexAtExit to register an exit function that MATLAB will call before it releases it's last reference to a mex file. If clearing causes your exit function to be hit but the mex file is not unloaded then some other activity is keeping it loaded.
  댓글 수: 5
Andrew Cunningham
Andrew Cunningham 2018년 8월 7일
Yup, you are right. I missed that one.If I create another counter local to that routine, it does get reset to 0. So it seems simple mex files do get unloaded. But my more complex ones with dependent DLL's do not so that remains a mystery.

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

태그

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by