35

I need to unload a DLL that was loaded with System.loadLibrary(..), anyone know if this is possible?

Lii
  • 9,906
  • 6
  • 53
  • 73
Alon Aizenberg
  • 1,486
  • 2
  • 18
  • 20

1 Answers1

31

I don't have any experience of this, but a bit of digging shows that the library should be unloaded when the classloader which loaded the library is garbage collected.

Links:

atoMerz
  • 6,868
  • 14
  • 56
  • 99
Jon Skeet
  • 1,261,211
  • 792
  • 8,724
  • 8,929
  • 1
    I just wasted 3 hours on this: The Java JNI DLL Unloading tutorial works, but **you cannot have a finalize() method in either your CustomClassLoader or your class that contains the native method!** I did not investigate why, but my guess is that it's related to the deprecation of finalize(). When removing the finalize from the example code everything works great! – mrexodia Mar 31 '20 at 14:18