David Heffernan 2383 Posted yesterday at 07:38 AM 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. 2 Share this post Link to post
Brandon Staggs 340 Posted yesterday at 06:16 PM I think this debate will never achieve any real consensus, and in the end, each of us needs to just decide what makes sense. Here's a nice fun read from 15 years ago: https://blog.therealoracleatdelphi.com/2010/02/a-case-against-freeandnil_5.html Interesting that Bauer and Primoz take opposite sides. 1 Share this post Link to post
Anders Melander 1911 Posted 5 hours ago (edited) 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 5 hours ago by Anders Melander 1 Share this post Link to post