David Heffernan 2402 Posted February 27 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 364 Posted February 27 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 1946 Posted February 28 (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 February 28 by Anders Melander 1 Share this post Link to post
GabrielMoraru 32 Posted March 4 (edited) On 2/21/2025 at 5:45 PM, Paul Dardeau said: Embarcadero hosted a youtube livestream the other day with MVPs. Where the hell is the link to that video. I wanted for over an year now to see that video. It was never released! Google does not know such video: https://www.google.com/search?client=firefox-b-d&q=free+and+nil+the+great+debate Edited March 4 by GabrielMoraru Share this post Link to post
DelphiUdIT 218 Posted March 4 (edited) Nothing ..... wrong replay Edited March 4 by DelphiUdIT Share this post Link to post
Lajos Juhász 316 Posted March 4 Just now, GabrielMoraru said: Where the hell is the link to that video. I wanted for over an year now to see that video. It was never released! 1 Share this post Link to post
GabrielMoraru 32 Posted March 4 (edited) My "3" cents: 1. FreeAndNil will definitively help you if you have stale pointers. 2. FreeAndNil costs only few more CPU cycles compared to Free(). 3. Some people with big mouth 🙂 suggested that FreeAndNil could be bad (somehow magically it will break your code), BUT nobody was able to post a piece of compilable code to prove it 🙂 . Until they do, they remain "big mouth" 🙂 . [Yes, this is a challenge] But, yes, don't design your code architecture around it. _ That being said, since it is so cheap to use it and might bring benefits, I do use it. PS: There were cases where it really helped. For example I had problems with a "use after free" in the ccrExif library. They were using an object after free. Replacing all .Free with FreeAndNil "magically" solved the "mystery". Edited March 4 by GabrielMoraru Share this post Link to post