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]

Loren Pechtel wrote:

> > But that is not what is going on here anyway. The destructor is
> > freeing INTERNAL private fields, to which only the code of the
> > instance has access. Since we are already in the destructor, the
> > only code that CAN access these fields are the few lines that
> > follow, and I expect any half intelligent programmer to be able to
> > prevent those from accessing a field that was freed a few lines
> > ago. After that, nothing can access them anymore.
> 
> Nope.  They're still accessible.
> 
> Remember that objects themselves are really just pointers and remain
> accessible even though they have been freed.

Well, your design will, of course, have to prevent that too. That means
that there is only one reference (except for local copies of the
reference, which disappear when the routine ends), and that is not
freed before it can be freed, i.e. not as long as it is accessible.
Follow that maxim and you can't access freed objects.
-- 
Rudy Velthuis (TeamB)        http://www.teamb.com

"Don't join the book burners."  -- Dwight D. Eisenhower
FYI: Phrase searches are enclosed in either single or double quotes
 
 
Originally created by
Tamarack Associates
Sun, 19 May 2024 20:45:24 UTC
Copyright © 2009-2024
HREF Tools Corp.