Destroy

 (Available in 01 TS COM - TS_COM_IUnknown)

Purpose

CALLBACK: This method will automaticly be called on the last 'Release()' call. Note: Never call this method directly, It will alwais be called on the last 'Release()'.

Syntax

// See the documentation for the 'Release()' method.
oSomeIClass:Release( ) 

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 'Release()' 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.

Note: Never call this method directly, It will alwais be called on the last 'Release()'.

Example

METHOD Destroy( ) CLASS SomeIClass
// 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_IUnknown
LOCAL ppIOwnedsArrayPP AS PTR PTR
LOCAL dwIOwnedsCount AS DWORD
LOCAL oIOwned AS TS_IUnknown
LOCAL oIIDs AS TS_PointerSafe
LOCAL X AS DWORD
   TSTrace Enter
   SELF:_ObjectStat1:=_OR( SELF:_ObjectStat1 ; ...
  ... , TS_OBJSTAT1_INDESTROY )
   ppIOwnedsArrayPP:=SELF:_IOwnedsArrayPP
   IF ppIOwnedsArrayPP<>NULL_PTR
      SELF:_IOwnedsArrayPP:=NULL_PTR
      SELF:_IOwnedsMax:=0
      dwIOwnedsCount:=SELF:_IOwnedsCount
      IF dwIOwnedsCount>0U
         SELF:_IOwnedsCount:=0U
         FOR X:=dwIOwnedsCount DOWNTO 1U
            IF ppIOwnedsArrayPP[ X ]<>NULL_PTR
               PTR( @oIOwned ):=ppIOwnedsArrayPP[ X ]
               ppIOwnedsArrayPP[ X ]:=NULL_PTR
               IF TS_IsValidObject( oIOwned, TS_ISVALID_STATIC_IUNKNOWN )
                  oIOwned:_InternalUnRegisterIOwner( SELF )
               ELSE
                  TSTrace Warning "!TS_IsValidObject(oIOwned,TS_ISVALID_STATIC_IUNKNOWN)"
               END
               oIOwned:=NULL_OBJECT
            END
         NEXT
      END
      TS_CoTaskMemFree( ppIOwnedsArrayPP )
      ppIOwnedsArrayPP:=NULL_PTR
   END
   IF SELF:_IOwner<>NULL_OBJECT
      IF SELF:_IOwner:_InternalUnRegisterIOwned( SELF  ; ...
     ... )
         SELF:_IOwner:OnUnRegisterIOwned( SELF )
         SELF:_IOwner:_InternalRelease( )
      END
      IF SELF:_IOwner<>NULL_OBJECT
         SELF:_IOwner:Release( )
         SELF:_IOwner:=NULL_OBJECT
      END
   END
   IF SELF:_IIDs<>NULL_OBJECT
      oIIDs:=SELF:_IIDs
      SELF:_IIDs:=NULL_OBJECT
      oIIDs:UnRegisterAxit( )
      oIIDs:Destroy( )
      oIIDs:=NULL_OBJECT
   END
   IF SELF:_IID<>NULL_PTR
      TS_MemFree( SELF:_IID, TRUE )
      SELF:_IID:=NULL_PTR
   END
   SELF:_ObjectStat1:=_OR( SELF:_ObjectStat1 ; ...
  ... , TS_OBJSTAT1_DESTROYED )
   SELF:_ObjectStat1:=_AND( SELF:_ObjectStat1 ; ...
  ... , _NOT( TS_OBJSTAT1_INDESTROY ) )
   TSTrace Leave DESTROY
RETURN NIL