I am loading a dll with ctypes like this:
lib = cdll.LoadLibrary("someDll.dll");
When I am done with the library, I need to unload it to free resources it uses. I am having problems finding anything in the docs regarding how to do this. I see this rather old post: How can I unload a DLL using ctypes in Python?. I am hoping there is something obvious I have not found and less of a hack.
The only truly effective way I have ever found to do this is to take charge of calling
LoadLibraryandFreeLibrary. Like this:Update:
As of Python 3.8,
ctypes.WinDLL()no longer acceptsNoneto indicate that no filename is being passed. Instead, you can workaround this by passing an empty string.See https://bugs.python.org/issue39243