Re: pointer components and memory leaks
  Home FAQ Contact Sign in
comp.lang.fortran only
 
Advanced search
POPULAR GROUPS

more...

 Up
Re: pointer components and memory leaks         

Group: comp.lang.fortran · Group Profile
Author: nospam
Date: Sep 16, 2008 12:13

Paul van Delst noaa.gov> wrote:
> Richard Maine wrote:
>> mrestelli@gmail.com gmail.com> wrote:
>>
>>> Dear all,
>>> is there a way to overload the operators +, =, ... for a derived
>>> type with pointer components which does not leak memory?
...
> and I still get the memory leak in tt_sum. It seems to me that this
> example will always leak somewhere inbetween the "+" and the "=".
> (only tried one compiler)
...
> The line
> c=a+b
> first calls tt_sum to do the "a+b" bit. Then tt_def is called to do the
> "c=..." bit. But what(or where) is the rhs of the assignment? The z result
> of tt_sum becomes the x input of tt_def...but where does the x input of
> tt_def "go" after the assignment is done?
>
> Crikey, trying to explain what I think I mean is confusing me.

That's ok. I'm following, at least adequately. I had forgotten all the
details, but I think you are right in that you also need a final
procedure to make that work without leaks. I haven't checked the exact
rules, but that's bound to be a context in which a final procedure is
invoked; anyway, it better be, that being one of the points of them. The
result of a+b is a temporary, which "goes away" after the assignment.
Final procedures are supposed to be called whenever something "goes
away" (though, of course, that's not the formal terminologuy used).

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
no comments
diggit! del.icio.us! reddit!