Fortran-95 comrades,
According to TR 15581, which specifies the behavior of allocatable
array components, allocatable components of a variable will be
deallocated when the variable is deallocated, and this behavior is
recursive so there are no memory leaks.
What happens if there is a hierarchy of types, a parent, say, a
child, and a grandchild, and the child doesn't have an allocatable
component, but the others do. Expanding the example in TR 15581:
program deallocation_example
type inner
real, allocatable :: ival(:)
end type
type middle
integer :: k
type (inner) :: middlecomp
end type
type outer
type (middle), allocatable :: ovalue(:)
end type
type (outer) :: x
allocate (x%ovalue(10))
allocate (x%ovalue(2)%middlecomp%ival(1000),
x%ovalue(5)%middlecomp%ival(9999))
deallocate (x%ovalue)
end
Does the deallocate statement deallocate everything allocated?
A similar question extends to assignments: Does an intrinsic assignment
do a "deep copy", as it is phrased in the report, for the following:
y = x
where both x and y are derived-type variables of type (outer) as defined
in the example?
Norm
|