Releasing Memory

The Java Virtual Machine (JVM) doesn't have an explicit method to allocate and free memory. For this reason, if the COBOL program gets a reference to an object from the JVM, it is the COBOL program's responsibility to release the reference, otherwise the JVM might exhaust machine resources.

To aid in this effort, we suggest that you establish a JVM trace file using the following configuration variables:

Using the JVM trace file, you can determine when a call to the JVM returns an object reference that must be released, then you can call C$JAVA with CJAVA_DESTROY or CJAVA_DELETE to remove the reference.

For there to be no memory leaks, any call that returns a reference to a Java object needs to be paired with a call to release that reference. When the runtime gets an object reference from the JVM, it is the runtime's responsibility to release the reference. When the runtime calls the JVM, it deletes the local reference to any memory the JVM allocated on behalf of the runtime.

In the JVM, an entity known as the JVM garbage collector also de-allocates memory that is no longer being used. To specify how often the runtime should call the JVM garbage collector, use the A_JAVA_GC_COUNT configuration variable.

See Configuration Variables for more information on these and other configuration variables.