From RAD Studio API Documentation
Jump to: navigation, search


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


__classmethod virtual TObject* __fastcall NewInstance();


Type Visibility Source Unit Parent
function public
System TObject


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