I have a Java tool that acts as a plugin to a 3D modeling app. I use JNI for most of the processing that the plugin does.
When the plugin is executed, the host app doesn''t terminate its VM (of course), so the JNI DLL remains in memory. Unfortunately, I''d prefer for the DLL to be reinitialized every time the plugin is run. This would make things a lot easier for me. Does anyone know if (and how) I can manually unload a DLL?
I may be wrong, but I believe you are at the mercy of the particular VM you are running on. I''m assuming between invocations of the plugin where are no global refrences to it that could be holding open the connection?
You MIGHT be able to use a proxy jni class that manages the loading and unloading for you, but that is idle specualtion.
i.e. implement the same interface and as part of each native source first checks if the DLL is loaded and if not load it. When you session is done ( or with a timier ) unload the .dll with part of the proxy class. The drawback is that you have 2 .dll''s one for the jni stub and the other .dll for the actual work. You also have to manage the .dll loading/unloading yourself.
However, if you need to do initialization every time it is loaded, why not just call some initialization routine in the DLL when you need it - to reinitialize its contents? There is no reason to put all initilization in DllMain(), besides maybe convenience.