Telling Java to free several objects at once
You can free many local references at once by calling the JNI function
PushLocalFrame before a section of RPG code that uses Java™ and then calling PopLocalFrame at the end
of the section of RPG code. When you call PopLocalFrame, any local
references created since the call to PushLocalFrame will be freed.
For more information about the parameters to these JNI functions,
see the JNI documentation at http://java.sun.com.
*----------------------------------------------------------------
* beginObjGroup - start a new group of objects that can all
* be deleted together later
*----------------------------------------------------------------
P beginObjGroup b export
D beginObjGroup pi 10i 0
D env * const
D capacityParm 10i 0 value options(*nopass)
D rc s 10i 0
D capacity s 10i 0 inz(100)
/free
JNIENV_p = env;
if (%parms >= 2);
capacity = capacityParm;
endif;
rc = PushLocalFrame (JNIENV_p : capacity);
if (rc <> 0);
return JNI_GROUP_NOT_ADDED;
endif;
return JNI_GROUP_ADDED;
/end-free
P beginObjGroup e
*----------------------------------------------------------------
* endObjGroup - end the group of objects that was started
* most recently
*----------------------------------------------------------------
P endObjGroup b export
D endObjGroup pi 10i 0
D env * const
D refObjectP o class(*java:'java.lang.Object')
D const
D options(*nopass)
D newObjectP o class(*java:'java.lang.Object')
D options(*nopass)
D retVal s o class(*java:'java.lang.Object')
D refObject s like(refObjectP) inz(*null)
D newObject s like(newObjectP)
/free
JNIENV_p = env;
if %parms() >= 2;
refObject = refObjectP;
endif;
newObject = PopLocalFrame (JNIENV_p : refObject);
if %parms() >= 3;
newObjectP = newObject;
endif;
return JNI_GROUP_ENDED;
/end-free
P endObjGroup e
Note: You need the JNI environment pointer (described in Obtaining the JNI environment pointer below) to call this wrapper.