System.TObject.NewInstance

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

class function NewInstance: TObject {$IFDEF AUTOREFCOUNT} unsafe {$ENDIF}; virtual;

C++

__classmethod virtual __unsafe TObject* __fastcall NewInstance();

Properties

Type Visibility Source Unit Parent
function public
System.pas
systobj.h
System TObject

Description

Allocates memory for an instance of an object type and returns a pointer to that new instance.

All constructors call NewInstance automatically. NewInstance calls InstanceSize to determine how much memory containing a particular instance to allocate from the heap. Do not call NewInstance directly.

Override NewInstance only for special memory allocation requirements. For example, when allocating a large number of identical objects that all need to be in memory at the same time, you can allocate a single block of memory for the entire group, then override NewInstance to use part of that larger block for each instance.

If you override NewInstance to allocate memory, you may need to override FreeInstance to deallocate the memory.

Note: By default, NewInstance calls InitInstance.

See Also