Dynamic Memory Allocation in Fortran

This document refers to Fortran 95. Do not presume that the features described here are present in other versions.

Allocation and Deallocation

Note the similarities and differences when using the following statements and functions.

ALLOCATE
This statement requests that memory be allocated for the pointer which it takes as an argument. Optionally also takes the named argument STAT with an integer variable to return a status code. Note that this is the same statement used to allocate memory for allocatable arrays.
DEALLOCATE
This statement requests that the memory previously allocated to the pointer which it takes as an argument be freed, and the pointer becomes disassociated. Optionally also takes the named argument STAT with an integer variable to return a status code.
ASSOCIATED
This function returns a logical indicating whether the pointer argument is associated (TRUE), disassociated (FALSE) or undefined (undefined i.e. TRUE or FALSE).
NULLIFY
This statement gives the pointer argument a status of disassociated.
NULL()
This function takes no arguments, but returns the null pointer. It is useful for initialising pointers to null by assignment in the declaration. Note that NULL() as introduced in F95 renders the NULLIFY statement redundant.