[Bug fortran/106750] Memory leak calling array slice of derived type containing `allocatable` entries
mikael at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Sun Sep 11 20:11:40 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106750
Mikael Morin <mikael at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mikael at gcc dot gnu.org
--- Comment #4 from Mikael Morin <mikael at gcc dot gnu.org> ---
Regarding the other "leak" from the original test:
(In reply to federico from comment #0)
>
> program test
(...)
> type(t), allocatable :: ts(:)
(...)
> ! [leak #2] happens if ts is not deallocated. Shouldn't a program work
> like a
> ! subroutine, and deallocate everything that's going out of scope?
> deallocate(ts)
>
> end program test
>
Not automatically deallocating is the correct behavior here, I think:
> A variable, (...) declared in the scoping unit of a main program, module, or
> submodule implicitly has the SAVE attribute
=> TS has the save attribute.
> The SAVE attribute specifies that a local variable of a program unit or
> subprogram retains its association status, allocation status, definition
> status, and value after execution of a RETURN or END statement (...).
=> TS is not deallocated at the end of the program
> 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 or a
> subobject thereof; otherwise, if it is allocated it will be deallocated.
=> this doesn’t apply as TS has the save attribute.
More information about the Gcc-bugs
mailing list