This article explains what to do when invoking a series of Object COBOL classes is producing an apparent memory leak.
Problem:
We are running a mainline COBOL application which loops calling / invoking a series of Object COBOL classes is producing an apparent memory leak. What should we do?
Resolution:
The most common cause of memory management problems associated with classes is a failure to finalize objects before exiting the program. The cause of the performance problem is a memory leak, the amount of memory allocated to the running process grows continually and in small incements on every iteration of the processing loop. The memory leak is occuring because there is one (or more) object invoked that is not finalized or deleted. To test for this condition do the following:
- Added the 'Behaviour class to the first class invoked i.e.
Behavior is class "behavior"
- Insert the following code just before the EXIT PROGRAM statement is executed:
invoke Behavior "getNumberOfObjects" returning totalNumber
Display "TotalNumber of objects is: " totalNumber
Running the application If the TotalNumber of objects grows by one or more on every iteration there are classes being inoked which are never finalized, each iteration will produce orphaned segments of memory, which degrades performance dramaticly.