System.TObject.DisposeOf
Delphi
procedure DisposeOf; {$IFNDEF AUTOREFCOUNT} inline; deprecated 'Use Free instead'; {$ENDIF}
C++
void __fastcall DisposeOf();
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
procedure function |
public | System.pas systobj.h |
System | TObject |
Description
DisposeOf forces the execution of the destructor code in an object.
It was an artifact from previous versions when the Delphi Mobile compilers supported Automatic Reference Counting. In current versions of Delphi, DisposeOf is used as a wrapper that invokes TObject.Free.
type
TMySimpleClass = class
private
stringMember: String;
constructor Create(const Text: String);
destructor Destroy;
end;
constructor TMySimpleClass.Create(const Text: String);
begin
stringMember := Text;
end;
destructor TMySimpleClass.Destroy;
begin
// this will be executed on calling the DisposeOf method.
end;
var
myObject: TMySimpleClass;
begin
myObject := TMySimpleClass.Create('This is a code snippet indicating the usage of the DisposeOf method');
try
// Use 'myObject' here
finally
myObject.DisposeOf;
end;
end.