Intel® Fortran Compiler 18.0 Developer Guide and Reference
Statement: Frees the storage allocated for allocatable variables and nonprocedure pointer targets (and causes the pointers to become disassociated).
DEALLOCATE (object[,object]...[, dealloc-opt])
object |
Is a structure component or the name of a variable, and must be a pointer or allocatable variable. |
||||
dealloc-opt |
(Output) Is one of the following:
|
If a STAT= variable or 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.
If an ALLOCATE or DEALLOCATE statement with a coarray allocatable object is executed when one or more images has initiated termination of execution, the STAT= variable becomes defined with the processor-dependent positive integer value of the constant STAT_STOPPED_IMAGE from the intrinsic module ISO_FORTRAN_ENV.
If any other error condition occurs during execution of the ALLOCATE or DEALLOCATE statement, the STAT= variable becomes defined with a processor-dependent positive integer value different from STAT_STOPPED_IMAGE.
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 Error Handling in the Compiler Reference.
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)