comp.lang.ada
 help / color / mirror / Atom feed
From: Brian May <bam@snoopy.apana.org.au>
Subject: Re: Possible Memory Leak
Date: Tue, 23 Nov 2004 10:00:06 +1100
Date: 2004-11-23T10:00:06+11:00	[thread overview]
Message-ID: <sa43bz1v6a1.fsf@snoopy.apana.org.au> (raw)
In-Reply-To: fealnc.6t.ln@127.0.0.1

>>>>> "R" == R A Matthews <ram@noone.nowhere> writes:

    R> This ensures that the target of the assignment is adjusted, so
    R> Self is set correctly and gives the target its own copy of the
    R> referenced data.

    R> BUT the Standard says that the temporary variable need not be
    R> finalized, in which case the temporary's data is not
    R> deallocated and so we have a memory leak.

Noone has responded - strange; I will bite.

I don't claim to be any expert, and I don't claim to completely
understand the problem either, but I suspect you are imagining a
problem where no problem exists.

The compiler will manage allocation and deallocation of temporary
variables, as required for you. If in doubt, either print a message in
each routine and see when it is executed, or look at the assembler
code.

In a previous post, I said:

Arr(1) := Empty expands into:

+ Temp := Empty;        -- shallow copy
+ Finalize(Arr(1));
+ Arr(1) := Temp;       -- shallow copy
+ Adjust(Arr(1));

This could also be written as:

+ Temp := Empty;        -- shallow copy
+ Finalize(Arr(1));
+ Adjust(Temp);
+ Arr(1) := Temp;       -- shallow copy

Where you can see that Temp is adjusted, and not finalised, but no
memory leak occurs either.

(disclaimer: I didn't check if this is what happens, however nobody
accused me of getting it wrong either...).
-- 
Brian May <bam@snoopy.apana.org.au>



  reply	other threads:[~2004-11-22 23:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-19 17:27 Possible Memory Leak R A Matthews
2004-11-22 23:00 ` Brian May [this message]
2004-11-23 19:09   ` RAMatthews
2004-11-23 21:21     ` Randy Brukardt
2004-11-23 21:17 ` Randy Brukardt
2004-11-25 17:49   ` RAMatthews
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox