Working storage variables persisting after class finalized in native code

A class had a method that used WORKING-STORAGE instead of LOCAL-STORAGE.  I created in instance of the class and set a variable in WORKING-STORAGE to a value, then finalized the instance.  I then created a new instance of the class and called the method.  The value from the last instance carried over into the new instance.  Is this expected behavior ?  It behaves the same way in Visual COBOL and Net Express 5.1.

I fixed this by using LOCAL-STORAGE instead of WORKING-STORAGE.

Parents
  • It's strange because WORKING-STORAGE and LOCAL-STORAGE sections are supposed to be equivalent within methods.  For instance the following program:

          class-id a.

          method-id main static.

          01 obj type a.

              set obj to new a

              perform 5 times

                  invoke obj::m

              end-perform

          end method.

          method-id m.

          working-storage section.

          01 i1 binary-long.

              add 1 to i1

              display i1

          end method.

          end class.

    ...shows the value '1' 5 times, since i1 is reinitialized on each entry to the method.

    I should say that the above is based on compiling the code to .NET or JVM.

Reply
  • It's strange because WORKING-STORAGE and LOCAL-STORAGE sections are supposed to be equivalent within methods.  For instance the following program:

          class-id a.

          method-id main static.

          01 obj type a.

              set obj to new a

              perform 5 times

                  invoke obj::m

              end-perform

          end method.

          method-id m.

          working-storage section.

          01 i1 binary-long.

              add 1 to i1

              display i1

          end method.

          end class.

    ...shows the value '1' 5 times, since i1 is reinitialized on each entry to the method.

    I should say that the above is based on compiling the code to .NET or JVM.

Children
No Data