Destroy

 (Available in 00 TS Tools(Base) - TS_Tools_Root1)

Purpose

CALLBACK: It is adviced to use 'oObject:Axit()'

Syntax

// See the documentation for the 'Axit' method.
oSomeClass:Axit( ) 

Description

This is where the application releases all refered to dynamicly allocated resources ( ARRAY, OBJECT, STRING ), and where all staticaly allocated memory is freed.

Note: Do not execute the 'Destroy()' method directly, it is adviced to call the 'Axit()' method when destruction of the object is needed this method of destruction is optimized for speed and guaranties that the 'Destroy()' method is only called once.

Note: The designer of the class should be aware of the fact that the 'Destroy()' method can be called multiple times.

Example

METHOD Destroy( ) CLASS SomeClass
// Let it be known that we are destroying the object
   SELF:IsInDestroy:=TRUE 
// Do the destructive work
   ... 
// All work should be done before calling SUPER
   SUPER:Destroy( ) 
RETURN NIL

Source

METHOD Destroy( ) CLASS TS_Root1
LOCAL oDestructor AS TS_Destructor
LOCAL aOwneds AS ARRAY
LOCAL oOwned AS OBJECT
LOCAL X AS DWORD
   TSTrace Enter
   SELF:_ObjectStat1:=_OR( SELF:_ObjectStat1 ; ...
  ... , TS_OBJSTAT1_INDESTROY )
   IF SELF:_Owneds<>NULL_ARRAY
      aOwneds:=SELF:_Owneds
      SELF:_Owneds:=NULL_ARRAY
      FOR X:=ALen( aOwneds ) DOWNTO 1
         oOwned:=aOwneds[ X ]
         aOwneds[ X ]:=NULL_OBJECT
         IF IsMethod( oOwned, #UnRegisterOwner )
            IF IsAccess( oOwned, #Owner )
               IF IVarGet( oOwned, #Owner )==SELF
                  oDestructor:=Send( oOwned, #UnRegisterOwner, SELF, TRUE )
                  IF oDestructor<>NULL_OBJECT
                     oDestructor:UnRegisterAxit( )
                     oDestructor:Destroy( )
                     oDestructor:=NULL_OBJECT
                  END
               END
            ELSE
               TSTrace Warning "!IsAccess(oOwned,#Owner)"
            END
         END
      NEXT
   END
   IF SELF:_Owner<>NULL_OBJECT
      IF !LOGIC( _CAST, _AND( SELF:_ObjectStat2, TS_OBJSTAT2_UNREGISTERED  ; ...
     ... ) )
         IF IsMethod( SELF:_Owner, #UnRegisterOwned )
            DO CASE
            CASE LOGIC( _CAST, _AND( SELF:_ObjectStat2, TS_OBJSTAT2_NOTREGISTERED  ; ...
           ... ) )
               SELF:_ObjectStat2:=_OR( SELF:_ObjectStat2 ; ...
              ... , TS_OBJSTAT2_UNREGISTERED )
            CASE IsMethod( SELF:_Owner, #UnRegisterOwned )
               IF Send( SELF:_Owner, #UnRegisterOwned, SELF,  ; ...
              ... TRUE )
                  SELF:_ObjectStat2:=_OR( SELF:_ObjectStat2 ; ...
                 ... , TS_OBJSTAT2_UNREGISTERED, TS_OBJSTAT2_NOTREGISTERED )
               ELSE
                  TSTrace Warning "!Send(SELF:_Owner,#UnRegisterOwned,SELF,TRUE)"
               END
            OTHERWISE
               SELF:_ObjectStat2:=_OR( SELF:_ObjectStat2 ; ...
              ... , TS_OBJSTAT2_UNREGISTERED, TS_OBJSTAT2_NOTREGISTERED )
            END
         ELSE
            SELF:_ObjectStat2:=_OR( SELF:_ObjectStat2 ; ...
           ... , TS_OBJSTAT2_UNREGISTERED, TS_OBJSTAT2_NOTREGISTERED )
         END
      END
      IF SELF:_Owner<>NULL_OBJECT
         IF IsMethod( SELF, #UnRegisterOwner )
            Send( SELF, #UnRegisterOwner, SELF:_Owner, FALSE  ; ...
           ... )
            IF SELF:_Owner<>NULL_OBJECT
               TSTrace Warning "SELF:_Owner<>NULL_OBJECT"
               SELF:_Owner:=NULL_OBJECT
            END
         ELSE
            SELF:_Owner:=NULL_OBJECT
         END
      END
   END
   SUPER:Destroy( )
   TSTrace Leave DESTROY
RETURN NIL