Instance data comes in extremely handy with WPS classes and is used throughout XWorkplace also. In all WPS programming docs and tutorials I've seen, you are taught to declare your instance data in the IDL file, initialize it in wpInitData, store it in wpSaveState, restore it in wpRestoreState, and clean up in wpUnInitData.

However, if your instance data consists of pointers to variable data which is allocated somewhere in the class's implementation (e.g. in wpInitData), great care must be taken to maintain data integrity.

When objects are copied, SOM per default does a so-called "shallow copy" of the object's instance data. That is, the binary instance data is simply copied to the new object. (From what I've seen, this is done by the SOMObject::somDefaultConstAssign method, which apparently is not overridden by any WPS class).

This is very dangerous for pointers because you then have two objects pointing to the same memory block. If one of the objects is then deleted and frees its storage (e.g. in wpUnInitData), the other object's member pointer points to storage which has been freed.

This problem is a common one with C++ programming, and there you have the concept of copy constructors to take it into account. Unfortunately, the WPS docs never even mention this problem, even though the WPS programmers have most obviously been aware of it, since WPS methods exist to solve this.

From my checking, there are two possible solutions to this problem:

I have checked some of the method tables (use the "WPS Class List" object to see yourself) and seen that many WPS classes override just these three methods (for example WPProgram, which most probably operates with pointers to store the program data which is variable in length). It is at least interesting to see that the WPS classes appear to use this approach, but not a word about this is said in the WPS docs...