Operator ‘__DELETE’¶
This operator is an extension of the IEC 61131-3 standard.
Attention
For compatibility, the compiler version must be >= 3.3.2.0.
The operator releases the memory of instances that the “__NEW” operator generated dynamically. The __DELETE
operator does not have a return value and the operand is set to zero after this operation.
Requirement: In the properties dialog box of the application, the Use dynamic memory allocation check box is selected in the Application build options tab.
__DELETE (<pointer>)
If Pointer
references a function block, then CODESYS calls the associated FB_EXIT
method before the pointer is set to zero.
Examples
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;
neu : BOOL;
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