Deallocation of allocatable class components of types

Deallocation of allocatable class components of types

Consider this:

    module memory
    implicit none

    Type :: MyType
        real X(50000)
    end type

    type M
        class(MyType), allocatable :: mem
!    final :: testfree
    end type

!    subroutine testfree(this)
!    Type(M) this
!    if (allocated(this%mem)) deallocate(this%mem)
!    end subroutine testfree

    subroutine local(A)
    Type (M) :: A, B


    end subroutine local

    subroutine testmem
    Type(M) :: X
    integer i

    do i=1, 1000
        call local(X)
    end do

    end subroutine testmem

    end module memory

My understanding is that allocatable components of types are supposed to be deep copied and deallocated automatically as appropriate. However calling "testmem" when compiled wtih ifort gives a memory leak, which can be fixed by uncommenting the explicit final. What exactly are the rules here, or is it a compiler bug? (changing the component to a Type rather than Class there is no leak).

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

It's a bug.

I think this is the same as our issue DPD200252621, described in  It is not yet fixed. I will verify that it's the same bug.

Retired 12/31/2016

Fixed in 15.0.

Retired 12/31/2016

Leave a Comment

Please sign in to add a comment. Not a member? Join today