## 6.2.1 Deallocation of Allocatable Arrays

If the DEALLOCATE statement specifies an array that is not currently allocated, an error occurs.

If an allocatable array with the TARGET attribute is deallocated, the association status of any pointer associated with it becomes undefined.

If a RETURN or END statement terminates a procedure, an allocatable array has one of the following allocation statuses:

- It keeps its previous allocation and association status if the following is true:
  - It has the SAVE attribute.
  - It is in the scoping unit of a module that is accessed by another scoping unit which is currently executing.
  - It is accessible by host association.
- It remains allocated if it is accessed by use association.
- Otherwise, its allocation status is deallocated.

The intrinsic function ALLOCATED can be used to determine whether an allocatable array is currently allocated; for example:

    SUBROUTINE TEST
      REAL, ALLOCATABLE, SAVE :: F(:,:)

      REAL, ALLOCATABLE :: E(:,:,:)
      ...
      IF (.NOT. ALLOCATED(E)) ALLOCATE(E(2:4,7,14))
    END SUBROUTINE TEST

Note that when subroutine TEST is exited, the allocation status of F is maintained because F has the SAVE attribute. Since E does not have the SAVE attribute, it is deallocated. On the next invocation of TEST, E will have the status of "not currently allocated".

For More Information:

- On host association, see Section 16.4.1.2.
- On the TARGET attribute, see Section 5.18.
- On the RETURN statement, see Section 7.9.
- On the END statement, see Section 7.6.
- On the SAVE attribute, see Section 5.17.

Previous Page Next Page Table of Contents