Jump to content
Paul Dardeau

Guidance on FreeAndNil for Delphi noob

Recommended Posts

4 hours ago, Darian Miller said:

One step further... I worked with a Delphi developer who rarely used Free, and tried to only use Destroy.  Everyone seems to have an opinion on Free vs FreeAndNil but he was the only one that ever went further and said Destroy vs Free.  Some of the same arguments could be had for using Destroy vs Free.  (But I still use .Free)

This one is easy to debunk. Exceptions raised in a constructor then lead to exceptions in the destructor. This is the entire reason why Free exists. 

  • Like 2

Share this post


Link to post
20 hours ago, Brandon Staggs said:

Interesting that Bauer and Primoz take opposite sides.

I can't see that they do.

 

Here's the TLDR as I read it:

Allen is saying that you shouldn't (mindless or not) use FreeAndNil to solve logic/design bugs and AFAICT nobody is disagreeing with that.

Primoz and David are saying that they are using it to find stale reference bugs.

 

Allen's suggestion to use a debug memory manager instead isn't valid because you can't do that on a production system, as Primoz also points out.

Edited by Anders Melander
  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×