DEALLOCATE

Statement: Frees the storage allocated for allocatable arrays and pointer targets (and causes the pointers to become disassociated).

Syntax

DEALLOCATE (object[,object]...[, alloc-opt])

object

Is a structure component or the name of a variable, and must be a pointer or allocatable array.

alloc-opt

(Output) Is one of the following:

STAT=sv

sv is a scalar integer variable in which the status of the deallocation is stored.

ERRMSG=ev

ev is a scalar default character value in which an error condition is stored if such a condition occurs.

Description

If a STAT variableor ERRMSG variable is specified, it must not be deallocated in the DEALLOCATE statement in which it appears. If the deallocation is successful, the variable is set to zero. If the deallocation is not successful, an error condition occurs, and the variable is set to a positive integer value (representing the run-time error); the ERRMSG variable contains the error condition. If no STAT variable is specified and an error condition occurs, program execution terminates.

It is recommended that all explicitly allocated storage be explicitly deallocated when it is no longer needed.

To disassociate a pointer that was not associated with the ALLOCATE statement, use the NULLIFY statement.

For a list of run-time errors, see Building Applications.

Example

The following example shows deallocation of an allocatable array:

INTEGER ALLOC_ERR

REAL, ALLOCATABLE :: A(:), B(:,:)

...

ALLOCATE (A(10), B(-2:8,1:5))

...

DEALLOCATE(A, B, STAT = ALLOC_ERR)

The following shows another example:

INTEGER, ALLOCATABLE :: dataset(:,:,:)

INTEGER reactor, level, points, error

DATA reactor, level, points / 10, 50, 10 /

ALLOCATE (dataset(1:reactor,1:level,1:points), STAT = error)

DEALLOCATE (dataset, STAT = error)

See Also