System.SysUtils.FreeAndNil

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

procedure FreeAndNil(var Obj);

C++

extern DELPHI_PACKAGE void __fastcall FreeAndNil(void *Obj);

Properties

Type Visibility Source Unit Parent
procedure
function
public
System.SysUtils.pas
System.SysUtils.hpp
System.SysUtils System.SysUtils

Description

Frees an object reference and replaces the reference with nil (Delphi) or NULL (C++).

Use FreeAndNil to ensure that a variable is nil (Delphi) or NULL (C++) after you free the object it references. Pass any variable that represents an object as the Obj parameter.

Warning: Obj must be an instance of a TObject descendant.

For C++, a reference to the object must be passed to FreeAndNil. For example:

TObject *obj = new TObject();
FreeAndNil(&obj);

See Also

Code Examples