I have a class that loads native library in static block. All other methods in the class are NOT static methods - so I need to instantiate the class to call methods on it.
------------------------------------------
class MyClass {
static {
System.loadLibrary("MyLibrary");
}
public native
string method1();
}
calling program method:
-------------------------------------------
{
.....
MyClass myClass = new MyClass();
String str = myClass.method1();
myClass = null; //allow it to be garbage collected
......
}
calling program method2:
{
.....
MyClass myClass = new MyClass();
String str = myClass.method1();
myClass = null; //allow it to be garbage collected
......
}
-----------------------------------------------------
Please someone tell me if my understanding is wrong:
The native library will be loaded when the class will be instantiated for the first very time. Even if I set the instance to null and if the object really gets garbage collected, because the native library is loaded from a static block, it still remains loaded and next time I instantiate the class (in calling program method2), it won't load that library again - is this thought process right???
Thanks,
P.Ingle