Newinstance

This instruction allocates a class or representation instance.

Syntax

RESULT = NewInstance CLASS_NAME AllocGroup NullRESULT = NewInstance CLASS_NAME AllocGroup OTHER_INSTANCE

With the first syntax, the engine creates a dedicated allocation group.

With the second syntax, we use the same allocation group as the instance called "OTHER_INSTANCE".

The allocation group simplifies memory management. When you free a given group, all the instances in the group will be freed at the same time.

The ALLOCGRP built-in property returns the allocation group of an instance. This can be useful for debug purposes, if you want to verify whether two instances belong to the same group or not.

Example

 # Declare customer and sales rep instanceLocal Instance MY_CUSTOMER Using C_CUSTOMERLocal Instance MY_SALESREP Using C_SALESREP# Allocate them in the same allocation groupMY_CUSTOMER = NewInstance C_CUSTOMER AllocGroup NullMY_SALESREP = NewInstance C_SALESREP AllocGroup MY_CUSTOMER...# Free themFreeGroup MY_CUSTOMER : # FreeGroup MY_SALESREP would have the same effect

Comment

The syntax of NewInstance and FreeInstance evolved since the beginning, and FreeGroup has been added. The old syntaxes using "With" keyword and an allocation group between brackets are deprecated and must no more be used.

See also

Structure, FreeInstance, FreeGroup, Instance, SetInstance, allocgrp, cast, null.