http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57762
Tobias Burnus <burnus at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |burnus at gcc dot gnu.org --- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> --- If it makes you happy, the following plugs the memory leak: --- a/gcc/testsuite/gfortran.dg/class_array_7.f03 +++ b/gcc/testsuite/gfortran.dg/class_array_7.f03 @@ -56,2 +56,3 @@ program main if (trim (print_type ("a", a)) .ne. "a is base_type") call abort + deallocate (a) end program main The reason is that gfortran no longer automatically deallocates allocatables at the end of the main program (with very few exceptions). That's in order to prevent finalization. Fortran 2008 has: "A variable, common block, or procedure pointer declared in the scoping unit of a main program, module, or submodule implicitly has the SAVE attribute, which may be conrmed by explicit specification." And: "4.5.6.3 When finalization occurs": "A nonpointer, nonallocatable object that is not a dummy argument or function result is finalized immediately before it would become undened due to execution of a RETURN or END statement (16.6.6, item (3))." which excludes SAVE: "(3) When execution of an instance of a subprogram completes, (a) its unsaved local variables become undefined," Okay, that was for nonallocatables - and we have an allocatable. But there the same applies: "When an allocatable entity is deallocated, it is finalized." and "When the execution of a procedure is terminated by execution of a RETURN or END statement, an unsaved allocatable local variable of the procedure retains its allocation and definition status if it is a function result variable or a subobject thereof; otherwise, it is deallocated." Before finalization entered the game, it was undetectable - within the program - whether the compiler deallocated variables in the main program or not. Now, it is no longer. Hence, there is no automatic deallocation - and you see the memory leak. See also http://gcc.gnu.org/wiki/GFortran#GCC4.9