This operator is not specified by the IEC 61131-3 standard.
For compatibility information, refer to the EcoStruxure Machine Expert/CoDeSys compiler version mapping table in the Compatibility and Migration User Guide.
The __DELETE operator deallocates the memory for objects allocated before via the __NEW operator.
__DELETE has no return value and its operand will be set to 0 after the operation.
Activate the option Use dynamic memory allocation in the Application build options view (View > Properties... > Application build options). Consult the Programming Guide specific to your controller for whether the options are available on your controller.
__DELETE (<pointer>)
If pointer is a pointer to a function block, the dedicated method FB_Exit will be called before the pointer is set to NULL.
NOTE: Use the exact data type of the derived function block and not that of the base function block. Do not use a variable of type POINTER TO BaseFB. This is necessary because if the base function block implements no FB_Exit function, then at the later usage of __DELETE(pBaseFB), no FB_Exit is called.
In the following example, the function block FBDynamic is allocated dynamically via _NEW from the POU PLC_PRG. By doing so, FB_Init method will be called, in which a type DUT is allocated. When __DELETE is called on, the function block pointer from PLC_PRG, FB_Exit will be called, which in turn frees the allocated internal type.
FUNCTION_BLOCK FBDynamic
VAR_INPUT
in1, in2 : INT;
END_VAR
VAR_OUTPUT
out : INT;
END_VAR
VAR
test1 : INT := 1234;
_inc : INT := 0;
_dut : POINTER TO DUT;
END_VAR
out := in1 + in2;
METHOD FB_Exit : BOOL
VAR_INPUT
bInCopyCode : BOOL;
END_VAR
__Delete(_dut);
METHOD FB_Init : BOOL
VAR_INPUT
bInitRetains : BOOL;
bInCopyCode : BOOL;
END_VAR
_dut := __NEW(DUT);
METHOD INC : INT
VAR_INPUT
END_VAR
_inc := _inc + 1;
INC := _inc;
PLC_PRG(PRG)
VAR
pFB : POINTER TO FBDynamic;
bInit: BOOL := TRUE;
bDelete: BOOL;
loc : INT;
END_VAR
IF (bInit) THEN
pFB := __NEW(FBDynamic);
bInit := FALSE;
END_IF
IF (pFB <> 0) THEN
pFB^(in1 := 1, in2 := loc, out => loc);
pFB^.INC();
END_IF
IF (bDelete) THEN
__DELETE(pFB);
END_IF