System.Finalize

From Appmethod Libraries
Jump to: navigation, search

Object Pascal

procedure Finalize(var V; [ Count: NativeUInt]); overload;
procedure Finalize(var V; [ Count: NativeUInt]); overload;

Properties

Type Visibility Source Unit Parent
procedure public System.pas System System

Description

Uninitializes a dynamically-allocated variable.

Finalize should be used only in Object Pascal code where a dynamically allocated variable is deallocated by other means than the Dispose procedure. Dynamic arrays can never be deallocated using the Dispose procedure, but can be freed by passing them to Finalize.

For global variables, local variables, objects, and dynamic variables deallocated using Dispose, the compiler generates code that finalizes all long strings, variants, and interfaces contained by the variable when the instance is destroyed.

If a dynamic variable meets the following two conditions, a call to Finalize is required to finalize the variable before it can be deallocated.

The variable is deallocated by other means than the Dispose standard procedure (for example, using FreeMem).

The variable contains long strings, variants, or interfaces, not all of which are empty or Unassigned.

Finalize simply sets all long strings to empty and all variants and interfaces to Unassigned, thus properly releasing any memory that was referenced by the long strings and variants.

In cases where several variables are deallocated in a contiguous memory block such as a dynamically allocated array of strings, the additional Count parameter can be specified to finalize all variables in one operation.

If the variable specified in a call to Finalize contains no long strings, variants, or interfaces, the compiler eliminates the call and generates no code for it.

See Also


Code Examples