Freegroup

This instruction frees the memory of an instance and all the instances sharing the same allocation group.

Syntax

FreeGroup INSTANCE_VAR
See [allocgrp](../4gl/allocgrp.md) and [NewInstance](../4gl/newinstance.md) for more information on instance allocation and allocation groups.

Example

# Declare two instancesLocal Instance MY_CUSTOMER Using C_CUSTOMERLocal Instance MY_SALESREP Using C_SALESREPLocal Instance MY_COUNTRY Using C_COUNTRY# Allocate both instances in the same allocation groupMY_CUSTOMER = NewInstance C_CUSTOMER AllocGroup NullMY_SALESREP = NewInstance C_SALESREP AllocGroup MY_CUSTOMERMY_SALESREP = NewInstance C_SALESREP AllocGroup MY_CUSTOMERMY_COUNTRY = NewInstance C_COUNTRY AllocGroup MY_SALESREP...# Free only the country instanceFreeInstance MY_COUNTRY : # MY_CUSTOMER and MY_SALESREP still allocated# Free the allocation group (this would have freed MYCOUNTRY also if it had not already been done)FreeGroup MY_CUSTOMER : # FreeGroup MY_SALESREP would have the same effect

Comment

`FreeGroup` frees the memory but does not change the pointers that refer to the resources. Using them after a `FreeGroup` will generate errors. It can be useful to reassign them to a `null` pointer.
Local Instance MY_CUSTOMER Using C_CUSTOMERMY_CUSTOMER=NewInstance C_CUSTOMER AllocGroup Null...FreeGroup MY_CUSTOMERMY_CUSTOMER=null

See also

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