Chapter Contents

Previous

Next
Object Class: _term

Object Class: _term



Deletes an object


Syntax
Details

Syntax

objectName._term( );


Details

To perform additional processing when you delete an object (for example, when you close any open data set or delete nested lists) you can write your own _term method to override the default _term method. However, if you do this, you should also invoke the super _term method (the _term method inherited from the parent class) so the object is deleted according to the parent class' specifications. Usually this should be the last step in your SCL method. After the super _term method is invoked, the object does not exist anymore. The object identifier is then invalid and the object cannot receive broadcast messages or methods.

When a FRAME application ends, the widgets and FRAME objects are deleted by running their _term methods, even if you override the _term method and omit a call to the _term method using the SUPER routine.

You do not have to override the _term method to delete most sublists of an object. If you define an instance variable in a class such as type LIST, sublist instance variables are tagged during object creation with a new list attribute, AUTODELETE. When the Object class _term method executes, it deletes the object with a new AUTODELETE option for DELLIST. When this option is used for DELLIST, any sublists that have the AUTODELETE option set are also deleted. This differs from the RECURSIVE option of DELLIST, since only sublists with AUTODELETE are affected. AUTODELETE is ignored if the sublist has the NODELETE attribute.

The default behavior for DELLIST is NOAUTODELETE, so existing use of the DELLIST function is not affected.

You may also set the AUTODELETE list attribute on other lists that you add to your object. For example, if your _init method allocates a list for the automatic instance variable SUBLIST, you can designate that list to be automatically deleted, as shown here:

if sublist then
  /* delete existing sublist */
rc = dellist(sublist, 'y autodelete');
sublist = makelist();
rc = setlattr(sublist, 'AUTODELETE');

You can test for the AUTODELETE attribute with HASATTR:

hasAutoDelete = hasattr(listid, 'AUTODELETE');

You can turn it off with

 rc = setlattr(listid,'NOAUTODELETE');

COPYLIST and SAVELIST preserve the AUTODELETE attribute. This means that if you execute COPYLIST for a list that is held in an object's instance variable, the COPY has the AUTODELETE attribute (as will any of its sublists, if the original sublists had AUTODELETE). If you assign that COPY to another instance variable of another object, for example, that list and its contents are deleted automatically when the second object is deleted.

For example, consider an object A with an instance variable LIST that contains the sublists S1 and S2. Object B is another object. Assume the objects' class define methods 'getSublist' and 'setSublist', which get and set the LIST instance variable.

a.getSublist(list);
 /* fetches inst var LIST */
 copy = copylist(list);
 b.setSublist(copy);
 /* sets inst var LIST*/
.
.
.
 b._term;

Since the list was not copied recursively, the list COPY (which has the AUTODELETE attribute) contains the sublists S1 and S2. When object B is deleted, its sublist LIST (which is the list COPY) is also deleted. Further, its sublists S1 and S2 are deleted, since they also have the AUTODELETE attribute. This situation is not common and is actually discouraged.

Another situation to consider but that should not be a problem is late deletion of automatic list instance variables. For example, if your class has an automatic list instance variable SUBLIST, you may have written your _term method as follows:

_term_: method;
   call super(_self_, '_term_');
   rc = dellist(sublist);
endmethod;

Now, the sublist is deleted automatically during the SUPER call so the DELLIST returns a nonzero value in RC since SUBLIST is not a valid listid. Normally, the SUPER _term is the last action of a _term method, so this should not be a major problem. Deleting the list before the SUPER _term is still fine but not always necessary.

The AUTOTERM feature exists to automatically invoke _term on all undeleted objects when an application terminates. The _term method will be sent to all objects in an unspecified order.

On the AF or AFAPPLICATION commands, use the AUTOTERM option to control the feature:

AF C=lib.cat.member.name AUTOTERM=option
AFA C=lib.cat.member.name AUTOTERM=option

You can also use the AFSYS command once an application is running:

 AFSYS AUTOTERM option
Option is one of the following:
ON enables the AUTOTERM features. AUTOTERM is on by default. Use this to enable it if it has been turned off.
OFF disables the AUTOTERM feature. The software will not invoke _term on objects at task termination time.
VERBOSE prints a NOTE: and dumps the object list of each object that still exists at task termination time. This works even if AUTOTERM is OFF; it serves as a debugging aid to identify which objects still exist but whose _term method has not run.
NOVERBOSE disables the VERBOSE option. NOVERBOSE the default.

You cannot combine options in one string; use separate AUTOTERM= options on the command line or use separate AFSYS commands.


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.