<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic missing finalizer call for array of types in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/missing-finalizer-call-for-array-of-types/m-p/1175171#M147211</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I noticed that when arrays of derived types are allocated in an (ordinary) way, no finalization is invoked at deallocation. Here is an example:&lt;/P&gt;
&lt;PRE class="brush:fortran; class-name:dark;"&gt;Module mod_tmp1
  Type :: tmp1
    Real, allocatable :: a(:,:)
  contains
    Final :: SubFinalizer
  end type tmp1
  Type tmp2
    type(tmp1), allocatable :: x
  end type tmp2
contains
  Subroutine SubFinalizer(this)
    Implicit none
    Type(tmp1), Intent(InOut) :: this
    write(*,*) "finalizer called"
  End Subroutine SubFinalizer
End Module mod_tmp1
Program Test
  use Mod_tmp1
  Type(tmp1), allocatable :: a,b(:)
  type(tmp2), allocatable :: c(:)
  integer :: i
  allocate(a,b(1),c(1))
  allocate(c(1)%x)
  write(*,*) "deallocate a"
  deallocate(a)
  write(*,*) "deallocate b"
  deallocate(b)
  write(*,*) "deallocate c"
  deallocate(c)
End Program Test&lt;/PRE&gt;

&lt;P&gt;with the output&lt;/P&gt;

&lt;PRE class="brush:bash; class-name:dark;"&gt;deallocate a
 finalizer called
 deallocate b
 deallocate c
 finalizer called&lt;/PRE&gt;

&lt;P&gt;Is this behavior is observed with ifort 19.04 and gfortran 9.1. I couldn't really find something in standard 2008 which rules out the finalization of "b".&lt;/P&gt;
&lt;P&gt;Any idea?&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 06 Oct 2019 08:14:58 GMT</pubDate>
    <dc:creator>may_ka</dc:creator>
    <dc:date>2019-10-06T08:14:58Z</dc:date>
    <item>
      <title>missing finalizer call for array of types</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/missing-finalizer-call-for-array-of-types/m-p/1175171#M147211</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I noticed that when arrays of derived types are allocated in an (ordinary) way, no finalization is invoked at deallocation. Here is an example:&lt;/P&gt;
&lt;PRE class="brush:fortran; class-name:dark;"&gt;Module mod_tmp1
  Type :: tmp1
    Real, allocatable :: a(:,:)
  contains
    Final :: SubFinalizer
  end type tmp1
  Type tmp2
    type(tmp1), allocatable :: x
  end type tmp2
contains
  Subroutine SubFinalizer(this)
    Implicit none
    Type(tmp1), Intent(InOut) :: this
    write(*,*) "finalizer called"
  End Subroutine SubFinalizer
End Module mod_tmp1
Program Test
  use Mod_tmp1
  Type(tmp1), allocatable :: a,b(:)
  type(tmp2), allocatable :: c(:)
  integer :: i
  allocate(a,b(1),c(1))
  allocate(c(1)%x)
  write(*,*) "deallocate a"
  deallocate(a)
  write(*,*) "deallocate b"
  deallocate(b)
  write(*,*) "deallocate c"
  deallocate(c)
End Program Test&lt;/PRE&gt;

&lt;P&gt;with the output&lt;/P&gt;

&lt;PRE class="brush:bash; class-name:dark;"&gt;deallocate a
 finalizer called
 deallocate b
 deallocate c
 finalizer called&lt;/PRE&gt;

&lt;P&gt;Is this behavior is observed with ifort 19.04 and gfortran 9.1. I couldn't really find something in standard 2008 which rules out the finalization of "b".&lt;/P&gt;
&lt;P&gt;Any idea?&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Oct 2019 08:14:58 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/missing-finalizer-call-for-array-of-types/m-p/1175171#M147211</guid>
      <dc:creator>may_ka</dc:creator>
      <dc:date>2019-10-06T08:14:58Z</dc:date>
    </item>
    <item>
      <title>Quote:may.ka wrote:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/missing-finalizer-call-for-array-of-types/m-p/1175172#M147212</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;may.ka wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;..&amp;nbsp;I couldn't really find something in standard 2008 which rules out the finalization of "b".&lt;/P&gt;&lt;P&gt;Any idea? ..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The shown implementation(SubFinalizer) in the original post for the 'final' generic only covers the rank-0 (scalar) attribute of an object to be finalized, one has to implement specific procedures for each rank that is to be supported for finalization, or consider the ELEMENTAL attribute for the final subroutine:&lt;/P&gt;
&lt;PRE class="brush:fortran; class-name:dark;"&gt;module mod_tmp1
   implicit none
   type :: tmp1
      real, allocatable :: a(:,:)
   contains
      final :: SubFinalizer
   end type tmp1
   type tmp2
      type(tmp1), allocatable :: x
   end type tmp2
contains
   impure elemental subroutine SubFinalizer(this) !&amp;lt;-- IMPURE only because of WRITE statement in the scope
      type(tmp1), intent(inout) :: this
      write(*,*) "finalizer called"
   end subroutine SubFinalizer
end module mod_tmp1
program Test
   use Mod_tmp1
   type(tmp1), allocatable :: a,b(:)
   type(tmp2), allocatable :: c(:)
   integer :: i
   allocate(a,b(1),c(1))
   allocate(c(1)%x)
   write(*,*) "deallocate a"
   deallocate(a)
   write(*,*) "deallocate b"
   deallocate(b)
   write(*,*) "deallocate c"
   deallocate(c)
end program Test
&lt;/PRE&gt;

&lt;P&gt;Upon execution,&lt;/P&gt;

&lt;PRE class="brush:plain; class-name:dark;"&gt; deallocate a
 finalizer called
 deallocate b
 finalizer called
 deallocate c
 finalizer called
&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Oct 2019 14:52:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/missing-finalizer-call-for-array-of-types/m-p/1175172#M147212</guid>
      <dc:creator>FortranFan</dc:creator>
      <dc:date>2019-10-06T14:52:00Z</dc:date>
    </item>
    <item>
      <title>Hi,
thanks.
Regards</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/missing-finalizer-call-for-array-of-types/m-p/1175173#M147213</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;thanks.&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Sun, 06 Oct 2019 15:00:32 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/missing-finalizer-call-for-array-of-types/m-p/1175173#M147213</guid>
      <dc:creator>may_ka</dc:creator>
      <dc:date>2019-10-06T15:00:32Z</dc:date>
    </item>
  </channel>
</rss>

