Deleting objects

You define a Sub Delete to specify the procedure that LotusScript® is to execute just before it deletes an object of the specified class. You can use the Delete statement to explicitly delete objects, or you can let LotusScript® delete the object automatically when it is no longer needed.

Sub Delete

A class's Sub Delete is called when LotusScript® deletes an object of that class. Sub Delete itself does not actually delete the object -- it performs termination housekeeping before the system reclaims the object's memory space so that it may be used to hold new objects. Sub Delete receives no parameters and returns no value.

Deleting an object using the Delete statement

When you use the Delete statement, LotusScript® deletes the object even if one or more variables contain references to the object. All object reference variables that contain references to the deleted object are automatically assigned the value NOTHING, and you can no longer refer to the object's members.

In this example, the variables anObj and otherObj are set to NOTHING. You can reuse these variables because they are still valid references; they simply contain NOTHING.

Class DemoObject
  Sub New
    Print "New" 
  End Sub
 
  Sub Delete
    Print "Delete" 
  End Sub
End Class

Dim anObj As New DemoObject
Dim otherObj As DemoObject
Set otherObj = anObj    
 ' Make Other refer to the same object.
Delete anObj     
 ' Set all the object's references to NOTHING.

If ( (anObj is NOTHING) And (otherObj is NOTHING)) Then _
  Print "Both anObj and otherObj are now NOTHING"