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.
29297 Discussions

Deallocation of allocatable class components of types

antony
Beginner
515 Views
Consider this:

    module memory
    implicit none

    Type :: MyType
        real X(50000)
    end type

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

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

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

    B=A

    end subroutine local

    subroutine testmem
    Type(M) :: X
    integer i

    allocate(MyType::X%mem)
    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).

0 Kudos
3 Replies
IanH
Honored Contributor III
515 Views

It's a bug.

0 Kudos
Steven_L_Intel1
Employee
515 Views

I think this is the same as our issue DPD200252621, described in http://software.intel.com/en-us/forums/topic/500281 ; It is not yet fixed. I will verify that it's the same bug.

0 Kudos
Steven_L_Intel1
Employee
515 Views

Fixed in 15.0.

0 Kudos
Reply