The code in your question is probably written by someone that doesn't know about FreeAndNil
. Or perhaps it was originally written before FreeAndNil
was added to the RTL. If you want to nil the reference then you may as well use FreeAndNil
. Writing it out longhand doesn't help.
The only real difference is that FreeAndNil
will set the reference to Nil
even if Free
raises. But your destructors should never raise anyway so this is not that big a deal in my view.
There is a common trap with FreeAndNil
. Because it takes an untyped parameter, you can pass it anything. For example you can pass an interface, a record etc. If you make this mistake then you usually end up with strange runtime errors.
I'm not going to get started on whether or not FreeAndNil
is an appropriate design choice. That topic has been covered in some depth elsewhere.