- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The deallocate of house is all you need. It will automatically deallocate all allocatable subcomponents.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page