action.skip

FREE Statement

The FREE statement releases memory allocated using the ALLOCATE statement.

General Format:

FREE { data-ptr-1 } …

Syntax:

data-ptr-n is a data item declared with USAGE POINTER.

General Rules:

  1. The FREE statement releases the memory referenced by data-ptr-1.
  2. Any BASED data item using data-ptr-1 as a memory reference no longer has a memory reference pointer.

Code Sample:

       IDENTIFICATION DIVISION. 
       PROGRAM-ID. FREE-1. 
       ENVIRONMENT DIVISION. 
       DATA DIVISION. 
       WORKING-STORAGE SECTION. 
       77 DATA-PTR-1        USAGE POINTER BASED. 
       77 DATA-PTR-2        USAGE POINTER. 
       77 DUMMY PIC X. 
       PROCEDURE DIVISION. 
       MAIN. 
      *FREEDATA-PTR 
      * 
              ALLOCATE DATA-PTR-1 INITIALIZED. 
              ALLOCATE 100 CHARACTERS INITIALIZED RETURNING DATA-PTR-2. 

              DISPLAY "ALLOCATE SUCCESSFUL!" LINE 10 COL 10. 

              FREE DATA-PTR-1, DATA-PTR-2. 

              DISPLAY "FREE-1 FINISHED!" LINE 11 COL 10. 
              ACCEPT DUMMY LINE 11 COL 30. 
              STOP RUN.