tags:

views:

499

answers:

2

Is there any way to unload a DLL which gets loaded in the application using System.load() API call.

+2  A: 

You have to use a separate ClassLoader to load the dll. The dll is only bound to the ClassLoader it was loaded with. When the ClassLoader isn't used anymore (means no references to the ClassLoader exist), the garbage collector will free your ClassLoader and unload your dll.

tangens
That's the easiest way. I've also used a stub library that performs the loading of the real one from within the JNI code, that way I controlled it's loading an unloading explicitly.
Petesh
@Petesh Could you explain your approach a bit more. How exactly you handled unloading part?
Kamal Joshi
A: 

Similiar question was answered some time ago :) You can read this: http://stackoverflow.com/questions/1433155/how-to-reverse-system-loadlibrary-in-java/1433196#1433196

pir0