Supported RPG Features

The fixed-format DEALLOC opcode frees heap storage previously allocated by ALLOC or REALLOC:

     D pBuf            S               *
     D wBuf            S             20A   BASED(pBuf)
     C                   ALLOC     20            pBuf
     C                   EVAL      wBuf = 'Hello'
     C                   DEALLOC(N)              pBuf

Factor 1 and Factor 2 must be blank. The result field is the basing pointer variable. Two operation extenders are available:

DEALLOC on a *NULL pointer is a silent no-op - no error is raised regardless of whether (E) or an ER indicator is specified.

Free-format DEALLOC

DEALLOC is also supported as a free-format opcode:

**FREE
dcl-s pBuf pointer;
dcl-s wBuf char(20) based(pBuf);
dealloc(en) pBuf;

The result is the basing pointer. The (E) and (N) extenders behave exactly as in fixed-format, and free-format additionally allows them to be combined as (EN) in a single extender (the fixed-format 10-character opcode field cannot hold both letters, so fixed-format uses (N) plus an ER indicator instead).

ALLOC and REALLOC have no free-format opcode form - free-format allocation uses the %ALLOC and %REALLOC built-in functions. DEALLOC keeps an opcode form because no built-in function frees storage.