Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

question about allocatable object

yjyincj
Beginner
464 Views
Hi all
If I declare a type as follows
type building
real(8),allocatable::floor(:)
real(8),allocatable::column(:)
end type building

Then I define
type(building),allocatable::house(:)
allocate(house(10)
do iHouse = 1,10
allocate(house(iHouse)%floor(2))
allocate(house(iHouse)%column(8))
end do

After some intermediate steps, I want to deallocate all the allocated objects (i.e., house(10) as well as house%floor,
house%column). I came up with two options to do this deallocation.

One option is simply one statement as:
deallocate(house)

Another option is:
do iHouse = 1,10
deallocate(house(iHouse)%floor)
deallocate(house(iHouse)%column)
end do
deallocate(house)

However, I have no idea whether these two options make difference. Thank you.
0 Kudos
1 Reply
Steven_L_Intel1
Employee
464 Views

The deallocate of house is all you need. It will automatically deallocate all allocatable subcomponents.
0 Kudos
Reply