Use the VERBOSE value when you invoke your application or while the application
is running. With VERBOSE, the software displays a note about any object that still
exists at task termination, and it dumps the object list to the log before
sending the _term method. Without VERBOSE, _term is invoked and no note is displayed
in the log. Using VERBOSE
as you develop your applications is helpful because it can highlight objects that
your application fails to delete.
In a few rare cases, you might begin to see program halts as your application completes.
These halts are often caused when one object is deleted and another object that references
it does not know that it has been deleted.
For example, consider a class named Manager that maintains a list of instances of
Message File objects. The Manager
class has a _term method that unconditionally sends _term to each item in its list
of Message File objects:
term: private method;
dcl num i;
do i=1 to listlen(msgObjs);
dcl object msgObj;
msgObj=getitemn(msgObjs,i);
msgObj._term();
end;
_self_._super();
endmethod;
However, when a task ends, AUTOTERM may send _term to a Message File object before running the Manager's _term, so the Manager's
list becomes stale (that is, it contains object identifiers of deleted
Message File objects). The proper fix in this and similar situations
is to verify other dependent objects in the _term before sending methods
to them. (In this case, the Message File object is not aware of the
Manager and therefore cannot ask the Manager to remove the object
identifier from the Manager's list of Message File objects.)
To determine whether
a number is a valid list identifier, use
Then, to determine whether a list identifier is an object identifier, use
(The 'O' is a letter O as in Object.) For example, the Manager's _term method is more
correctly implemented as follows:
term: private method;
dcl num i;
do i=1 to listlen(msgObjs);
dcl object msgObj;
msgObj=getitemn(msgObjs,i);
if listlen(msgObj) > -1 and hasattr(msgObj,'O') then
msgObj._term();
end;
_self_._super();
endmethod;
Note: As an alternative to the
above solution, when _term is
run on a Message File object, the Message File object could send an
event. The manager would then have a handler for the event and could
remove the object from its list.