Another possibility to consider is the combination allocatable, target. This gives you some of the advantages of allocatables, such as automatic deallocation, while still allowing you to have multiple pointers that point to the underlying data. For example, a doubly linked list can be implemented this way, with the allocatable component allowing you to move forward through the list, and with the pointer component allowing you to move backwards through the list. Then the whole list is automatically deallocated when it goes out of scope, or when the first element is deallocated.
1 Like