Previous Topic Next topic Print topic


Canceling a COBOL Program

Restriction: This applies to native code only.

To prevent memory leaks you should cancel any COBOL programs you have loaded from Java before the owning Java object is subjected to garbage collection. Use the following call from the Finalize method of the Java object:

RuntimeSystem.cobcancel("program")

where program is the name of a COBOL program loaded using a RuntimeSystem.cobload() call. The following is an example of a Finalize method in a Java program:

private void Finalize()
	  {
       try
	      {
            RuntimeSystem.cobcancel("demoFinalizers");
            System.out.println("demoFinalizers - finalize'ed");
         }
       catch(Exception e)
         {
           System.out.println(
                "Error during finalize : "+e.getMessage());
		     }
		  }
CAUTION:
  • You should only cancel a program when you are sure you that no other program is using the program. This might be difficult in a server/threaded program.
  • This method is "Finalize" not "finalize" as we do not want the instance to be called during garbage collection as this may cause a memory block in the garbage collection process.
Previous Topic Next topic Print topic