Article

From:
To:
Joanna Carter
Subject:
Re: FreeAndNil is often sign of wrong design - did anyone really readthe blog? [Edit]
Newsgroup:
embarcadero.public.delphi.language.delphi.general

Re: FreeAndNil is often sign of wrong design - did anyone really readthe blog? [Edit]

"Joanna Carter" <✉no.spam.for.me> wrote in message 
news:✉forums.codegear.com...
> Loren Pechtel a __crit :
>
>> tFoo still can.  The dead instance of tFoo can still be referenced.

Exactly. And anybody having a reference can call methods on that reference 
that access the inner object.

> TFoo is a classnot an instance. Unless you still have a reference to an
> instance of TFoo, then you can't access the dead instance.

Finally...

> And, if your code calls the destructor on anything other than the last
> reference left alive, then you have a logic error.

It is not just about calling the destructor ... Any method on a dead 
instance can be called and any method can (and is allowed) access the 
private inner instances.

> Good programmers know to only create and destroy within the same scope.
> Any other references to the same object have absolutely no right to call
> the destructor. It's a question of ownership - there should only ever be
> one owner of any instance - all other references are non-owning and must
> not destroy it.

I prefer not to rely on rules alone. People are fallible, including me. I 
therefore prefer to employ runtime strategies as well that help me find 
infringements of the rules as immediately as possible.
--
Marjan Venema
FYI: Click here to see how many newsgroups are indexed
 
 
Originally created by
Tamarack Associates
Sun, 19 May 2024 20:45:24 UTC
Copyright © 2009-2024
HREF Tools Corp.