If you have created an object using a Java™ constructor, or if you have called a Java method that returned an object to you, this object will only be available to be destroyed by Java's garbage collection when it knows you do not need the object any more. This will happen for a native method (called by java) when the native method returns, but otherwise it will never happen unless you explicitly inform Java that you no longer need the object. You do this by calling the RPG wrapper procedure freeLocalRef.
CALLP freeLocalRef (JNIEnv_P : string);
Figure 1 contains the sample source code for freeLocalRef.
/*------------------------------------------------------*/
/* freeLocalRef */
/*------------------------------------------------------*/
P freeLocalRef...
P B EXPORT
D freeLocalRef...
D PI
D env * VALUE
D localRef O CLASS(*JAVA
D : 'java.lang.Object')
D VALUE
/free
jniEnv_P = env;
DeleteLocalRef (env : localRef);
/end-free
P freeLocalRef...
P E