I'm using JNA to load a native Library using:

```
MyLibrary INSTANCE = (MyLibrary) Native.loadLibrary("mylibrary.so", MyLibrary.class);

```

Now I want to clean up and dispose the library. I've read about the `dispose` method but this is defined on the class `NativeLibrary`, how I am supposed to call this?

Anyway, is it necessary to do that? I'm using jna with Apache Spark on a large scale, so I'm loading the library thousand of times, I'm wondering of there are any resources left open if I do nit excplicitly call `dispose`?

EDIT: I've seen the question [Jna, Unload Dll from java class dynamically](https://stackoverflow.com/questions/19999845/jna-unload-dll-from-java-class-dynamically), but it does not provide a solution to my problem.

There is no accepted answer. People suggest to call `NativeLibrary.dispose()`, but there is no such static method in `NativeLibrary`. If I try to cast my library instance (which is of type `Library`), then I get a class-cast exception.