Re: Allocatable Components of Derived Type



Oskar Enoksson <nobody@xxxxxxxxxxx> wrote:

Richard Maine wrote:

2. You can generalize that to all uses of allocatable. Allocatables
don't cause memory leaks. Unless, of course, there is a compiler bug.

One exception I guess is an allocatable array declared in a subroutine
with the "SAVE" attribute(?)

No. There are *NO* exceptions.

Such a case will not cause a memory leak, as normally defined. Perhaps
you are talking about the fact that such an array remains allocated
after the return. That's the only thing I can even imagine that you
might be aluding to. That is true, but that does not meet the usual
definition of a memory leak. The memory in question is not "lost". If
you reenter the subroutine, it will still be accessible, that being the
whole point of SAVE. If you try to allocate the array again without
deallocating it first, you won't leak the memory of the first
allocation; instead, you will get an error.

Absent compiler bugs, allocatables do not leak memory. There are no
exceptions. This is by deliberate design. If you actually know of any
exceptions, I'd suggest turning in a defect report to the standard
committee because that would be a defect. It did take a long time to
plug all the holes. I suppose it is vaguely possible that one is left
somewhere, though I don't think so. Certainly it would be nothing as
simple and obvious as a local allocatable variable with the SAVE
attribute. That *IS* a simple case.

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
.



Relevant Pages

  • Re: iso_varying_string in f2003?
    ... > possible to allocate something and then not deallocate it... ... That's not a memory leak. ... > to the array on return to the main program? ...
    (comp.lang.fortran)
  • Re: Allocatable Components of Derived Type
    ... One exception I guess is an allocatable array declared in a subroutine ... Such a case will not cause a memory leak, ... If you try to allocate the array again without ... exceptions, I'd suggest turning in a defect report to the standard ...
    (comp.lang.fortran)
  • RE: Can this cause memory leak ?
    ... No memory leak to worry about. ... it is inefficient and bad practice to catch exceptions ... during the normal flow of your code. ... > But I worry there is memory leak for lack the Deletecall. ...
    (microsoft.public.vc.language)
  • App issues with CE 5.0
    ... released and a memory leak results. ... creating but not destroying threads. ... that resulted in exceptions and these exceptions were traced to ATL. ... replaced the ATL SDK and atlce400.dll files with those from CE 4.0 and ...
    (microsoft.public.windowsce.platbuilder)
  • Re: SerialPort Class
    ... I've experienced sudden stops (no exceptions) due to a memory leak. ... method until a 'special character is received or a timeout elapses. ...
    (microsoft.public.dotnet.framework.compactframework)