Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29280 Discussions

question about allocatable object

yjyincj
Beginner
470 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
470 Views

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