## 6.2.2 Deallocation of Pointer Targets

A pointer must not be deallocated unless it has a defined association status. If the DEALLOCATE statement specifies a pointer that has undefined association status, or a pointer whose target was not created by allocation, an error occurs.

A pointer must not be deallocated if it is associated with an allocatable array, or it is associated with a portion of an object (such as an array element or an array section).

If a pointer is deallocated, the association status of any other pointer associated with the target (or portion of the target) becomes undefined.

Execution of a RETURN or END statement in a subprogram causes the pointer association status of any pointer declared (or accessed) in the procedure to become undefined, unless any of the following applies to the pointer:

- 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 is in blank common.
- It is in a named common block that appears in another scoping unit that is currently executing.
- It is the return value of a function declared with the POINTER attribute.

If the association status of a pointer becomes undefined, it cannot subsequently be referenced or defined.

Examples

The following example shows deallocation of a pointer:

    INTEGER ERR
    REAL, POINTER :: PTR_A(:)
    ...
    ALLOCATE (PTR_A(10), STAT=ERR)
    ...
    DEALLOCATE(PTR_A)

For More Information:

- On pointers, see Section 5.15.
- On host association, see Section 16.4.1.2.
- On the RETURN statement, see Section 7.9.
- On the END statement, see Section 7.6.
- On the SAVE attribute, see Section 5.17.
- On common blocks, see Section 5.4.
- On the NULL intrinsic function, which can be used to disassociate a pointer, see Section 9.3.111.

Previous Page Next Page Table of Contents