DEALLOCATE

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

Syntax

DEALLOCATE (object [, object] ...[, STAT=sv])

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

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

Rules and Behavior

If a STAT 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). 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 Visual Fortran Run-Time Errors in Error Messages.

Compatibility

CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB

See Also: ALLOCATE, NULLIFY, Arrays

Examples

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)