Delphi How To Force Execution Of The Destructor Code In An Object

FireWind

Свой
Регистрация
2 Дек 2005
Сообщения
1,957
Реакции
1,199
Credits
4,009
How To Force Execution Of The Destructor Code In An Object
By Muhammad Azizul Hakim December 9, 2021

The DisposeOf method or DelphiVCL.Application.DisposeOf forces the execution of the destructor code in an object.

After the DisposeOf method is called, the object is placed in a special state, the Disposed state. This means that the destructor is not called again if DisposeOf is called again, or if the reference count reaches zero (the moment in which the memory is released).

Are there any things to be aware of when using the DisposeOf method?​

The behavior of DisposeOf differs for the two generations of Delphi compilers:
  • On the Delphi desktop compilers (DCC32, DCC64, DCCOSX), the effect of calling DisposeOf remains the same, as it calls Free.
  • On the Delphi mobile compilers (DCCIOS32, DCCIOSARM), the destructor code is executed at the same time as for the Delphi desktop compilers, but the memory is managed by the Automatic Reference Counting mechanism.
Let’s browse all the properties and methods of the DelphiVCL.Application.DisposeOf using dir() command:
Python:
import DelphiVCL
 
dir(DelphiVCL.Application.DisposeOf)
See the responses in our Windows command prompt:
1639035616999.png
You can also read short information about the DelphiVCL.Application.DisposeOf using the print() command:
Python:
print(DelphiVCL.Application.DisposeOf)
print(DelphiVCL.Application.DisposeOf.__doc__)
See the responses in our Windows command prompt:
1639035652128.png