[fpc-pascal] Checking if a TStringList already exists
Michael Van Canneyt
michael at freepascal.org
Tue May 21 14:40:15 CEST 2019
On Tue, 21 May 2019, Graeme Geldenhuys wrote:
> On 20/05/2019 11:01 pm, Giuliano Colla wrote:
>> In some rare case when dealing with complex objects you might need
>> FreeThenNil() in place of FreeAndNil().
>
> As far as I'm concerned, that is such a broken concept! The developer
> already has the burden to free any memory that he/she allocates. With
> what you are saying, it is now expected from the developer to look at
> all source code, flip and coin to decide how complex it is (that will
> vary between developers) and then decide which Free(Then|And)Nil()
> function to call!? That should really be left up to the compiler and
> should be of no concern to the developer.
>
> Or there is a much simpler answer - the code the developer is working on
> is severely broken and needs some refactoring and decoupling of
> dependencies.
I'm with Graeme on this one.
FreeThenNil should never be necessary.
FreeAndNil() should be enough for all circumstances.
Michael.
More information about the fpc-pascal
mailing list