diff --git a/src/Utilities/CharString.f90 b/src/Utilities/CharString.f90 index cc6b3e107cd..3e84ddcec48 100644 --- a/src/Utilities/CharString.f90 +++ b/src/Utilities/CharString.f90 @@ -31,6 +31,7 @@ module CharacterStringModule procedure :: charstring_eq_charstring procedure :: write_unformatted procedure :: strlen + procedure :: destroy generic :: assignment(=) => assign_to_charstring, assign_from_charstring generic :: operator(==) => character_eq_charstring, & charstring_eq_character, & @@ -38,7 +39,6 @@ module CharacterStringModule ! not supported by gfortran 5 and 6 ! disable for now ! generic :: write (unformatted) => write_unformatted - final :: destruct end type CharacterStringType contains @@ -128,9 +128,9 @@ function strlen(this) result(length) end if end function strlen - subroutine destruct(this) - type(CharacterStringType), intent(inout) :: this + subroutine destroy(this) + class(CharacterStringType), intent(inout) :: this if (allocated(this%charstring)) deallocate (this%charstring) - end subroutine destruct + end subroutine destroy end module CharacterStringModule diff --git a/src/Utilities/Idm/mf6blockfile/Mf6FileGridInput.f90 b/src/Utilities/Idm/mf6blockfile/Mf6FileGridInput.f90 index 10a99576d13..5ceb05cf97b 100644 --- a/src/Utilities/Idm/mf6blockfile/Mf6FileGridInput.f90 +++ b/src/Utilities/Idm/mf6blockfile/Mf6FileGridInput.f90 @@ -220,7 +220,7 @@ end subroutine bndgrid_rp subroutine bndgrid_destroy(this) class(BoundGridInputType), intent(inout) :: this !< Mf6FileGridInputType ! - ! deallocate objects + ! deallocate tasmanager call this%tasmanager%da() deallocate (this%tasmanager) nullify (this%tasmanager) diff --git a/src/Utilities/Idm/mf6blockfile/Mf6FileListInput.f90 b/src/Utilities/Idm/mf6blockfile/Mf6FileListInput.f90 index 0b34426ea08..e3906f1d3f5 100644 --- a/src/Utilities/Idm/mf6blockfile/Mf6FileListInput.f90 +++ b/src/Utilities/Idm/mf6blockfile/Mf6FileListInput.f90 @@ -170,7 +170,7 @@ end subroutine bndlist_rp subroutine bndlist_destroy(this) class(BoundListInputType), intent(inout) :: this !< BoundListInputType ! - ! deallocate objects + ! deallocate tsmanager call this%tsmanager%da() deallocate (this%tsmanager) nullify (this%tsmanager) diff --git a/src/Utilities/Idm/mf6blockfile/StructArray.f90 b/src/Utilities/Idm/mf6blockfile/StructArray.f90 index c9c194d19a3..c447a3da02b 100644 --- a/src/Utilities/Idm/mf6blockfile/StructArray.f90 +++ b/src/Utilities/Idm/mf6blockfile/StructArray.f90 @@ -481,6 +481,7 @@ subroutine load_deferred_vector(this, icol) this%mempath) do i = 1, this%nrow p_charstr1d(i) = this%struct_vectors(icol)%charstr1d(i) + call this%struct_vectors(icol)%charstr1d(i)%destroy() end do end if @@ -668,6 +669,7 @@ subroutine check_reallocate(this) do i = 1, this%struct_vectors(j)%size p_charstr1d(i) = this%struct_vectors(j)%charstr1d(i) + call this%struct_vectors(j)%charstr1d(i)%destroy() end do deallocate (this%struct_vectors(j)%charstr1d) diff --git a/src/Utilities/Memory/Memory.f90 b/src/Utilities/Memory/Memory.f90 index f6e75b2fbc2..5d4d6363f12 100644 --- a/src/Utilities/Memory/Memory.f90 +++ b/src/Utilities/Memory/Memory.f90 @@ -99,6 +99,7 @@ end function mt_associated subroutine mt_deallocate(this) class(MemoryType) :: this + integer(I4B) :: n if (associated(this%strsclr)) then if (this%master) deallocate (this%strsclr) @@ -156,7 +157,12 @@ subroutine mt_deallocate(this) end if if (associated(this%acharstr1d)) then - if (this%master) deallocate (this%acharstr1d) + if (this%master) then + do n = 1, size(this%acharstr1d) + call this%acharstr1d(n)%destroy() + end do + deallocate (this%acharstr1d) + end if nullify (this%acharstr1d) end if end subroutine mt_deallocate diff --git a/src/Utilities/Memory/MemoryManager.f90 b/src/Utilities/Memory/MemoryManager.f90 index 9d6cca3305d..ec67a0b24b4 100644 --- a/src/Utilities/Memory/MemoryManager.f90 +++ b/src/Utilities/Memory/MemoryManager.f90 @@ -1223,6 +1223,7 @@ subroutine reallocate_charstr1d(acharstr1d, ilen, nrow, name, mem_path) ! -- copy existing values do n = 1, nrow_old astrtemp(n) = acharstr1d(n) + call acharstr1d(n)%destroy() end do ! ! -- fill new values with missing values @@ -1242,6 +1243,7 @@ subroutine reallocate_charstr1d(acharstr1d, ilen, nrow, name, mem_path) ! -- fill the reallocated character array do n = 1, nrow acharstr1d(n) = astrtemp(n) + call astrtemp(n)%destroy() end do ! ! -- deallocate temporary storage @@ -2009,6 +2011,7 @@ subroutine deallocate_charstr1d(astr1d, name, mem_path) type(MemoryType), pointer :: mt logical(LGP) :: found type(MemoryContainerIteratorType), allocatable :: itr + integer(I4B) :: n ! -- code ! ! -- process optional variables @@ -2033,6 +2036,9 @@ subroutine deallocate_charstr1d(astr1d, name, mem_path) terminate=.TRUE.) else if (mt%master) then + do n = 1, size(astr1d) + call astr1d(n)%destroy() + end do deallocate (astr1d) else nullify (astr1d)