DEALLOCATE statement

Standard: F77 F90 F95 F2003 F2008 F2018 Example program


<Syntax>

DEALLOCATE( object [ , object ]... [, option ]... )

option ::= ERRMSG = variable
| STAT = variable

Each object must be a pointer or allocatable variable. The variable for STAT= must be a scalar integer, and should be able to represent values in the range −9999 to +9999. The variable for ERRMSG= must be a scalar character of default kind. Only one of each kind of option is allowed.

<Semantics>

The DEALLOCATE statement deallocates storage occupied by an allocatable variable or pointer. An error is raised if an allocatable variable to be deallocated is not allocated, or if a pointer to be deallocated is disassociated or is associated with an object that was not allocated by pointer allocation.

Deallocating a pointer sets that pointer to "disassociated" but any other pointers associated with the target become undefined. Similarly, any pointers associated with an allocatable variable become undefined when the variable is deallocated.

The STAT= variable is set to zero if all the deallocations were successful or to a non-zero error code if an error occurred; if an error occurs when no STAT= is used, the program is terminated.

In Fortran 2003 the ERRMSG= specifier was added; this sets a character string variable to an error message if a deallocation fails. The variable is unchanged if there is no error.

<Related>

ALLOCATABLE attribute, ALLOCATE statement, ERRMSG= specifier, MOVE_ALLOC intrinsic subroutine, NULLIFY statement, POINTER attribute, STAT= specifier