unloadlibrary still keeps the library loaded!
Show older comments
Hello,
I have a socket communication framework wrapped inside of a library (dll). I can use it by using loadlibrary. That works fine. My problem is that calling unloadlibrary doesn't generate any error (the first time it is called), but then it appears that the library is still in memory: if I try to delete the shared library file (the dll file), Windows complains saying that some other application is using it. Only after quiting Matlab will I be able to successfully delete the library file. That makes me think: unloadlibrary is not doing its job, since Matlab is still keeping it in memory.
Am I missing something?
Answers (2)
Philip Borghesani
on 19 Nov 2015
0 votes
The problem most is most likely with your library not with MATLAB. When a library is loaded the operating system increases the load count for the library by one and unloadlibrary decrements it by one. If the count goes to 0 the operating system has the option of unloading it. Doing so is not mandatory... Any other library loading the library you are using or the library itself may be locking itself into memory by calling loadlibrary on itself.
Many libraries do not work correctly if unloaded and reloaded. Calling unloadlibrary should be considered optional.
With windows com dlls the unload is deliberately delayed to prevent thrashing when the dll is unloaded and reloaded in rapid succession.
Categories
Find more on Call C from MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!