SIMPOL Documentation

Variable and Object Persistence

"Variables are like the glue that holds everything together." This description is especially appropriate in SIMPOL, since any object that is no longer referred to by any variable anywhere within the program will immediately be discarded. This is an important point to understand. If an object is no longer referenced in any way by the program, via a variable or a property of an object that is itself referenced by a variable it will be discarded. Even if there is a linked list of objects each of which refers to the next, as long as the beginning of the list is anchored by being referred to by a variable the entire list will still exist. Once there is no way for the program to refer to the beginning of the list, any object not referred to by a variable will be discarded. If the third element of the list is still referred to by a variable but the base is not, then the base and all elements preceding the third member will be discarded. If, however, each object in the list has a property that refers to the preceding object as well as one that refers to the next object (a doubly-linked list) then as long as any member of the list is referred to by a variable (or by another object that is anchored by a variable) then the entire list is safe and will not be discarded.

This allows for the creation and use of quite complex data structures in memory while only retaining a single base variable to anchor the entire structure. Once a function is exited, all local variables created within the function are destroyed. If the local variable were in the parameter list, then the corresponding variable in the calling function will be assigned the value of the local variable prior to the variable being destroyed.

An important point to remember is that if a variable is passed to a function and the variable has not yet been initialized to refer to an object, then it cannot receive any changes made within the original function since no object exists to assign the results to. Also, it is not possible to create an object in a function and assign it to a local variable and then have that object returned to the calling function. The only way to do this is to have the new object be the return value of the called function and to assign the results of the function call using the object reference assignment operator (=@).