# 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)

Parent topic: Effects of Deallocation

## See Also

POINTER statement and attribute
COMMON statement
NULL intrinsic function
Host association
TARGET statement and attribute
RETURN statement
END statement
SAVE statement