Hi,

JNI_OnLoad has a companion JNI_OnUnload [1], which is the perfect place to invoke an env->DeleteGlobalRef(MyWhateverClass), allowing the JVM garbage collector to do a proper cleanup.

Kind regards,
Antonio

[1] https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/invocation.html#JNI_OnUnload

El 8/4/21 a las 5:28, Jaroslav Tulach escribió:
JNI_OnLoad(...) {
    // Find the class in OnLoad
    jclass clazz = env->FindClass(...);
    // And keep a NewGlobalRef for future use...
    MyWhateverClass = env->NewGlobalRef(clazz);
...
That's the recommended approach. However it shall be stated that this is
creating a (class loading) memory leak - it is not going to be possible to
unload the JavaFX JAR file classes once this variable is initialized. Just FYI,
I think we can live with such behavior.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists



Reply via email to