That all already exist. The
FreeAndNil is a habit of some programmers to hide their own bugs, but generally many - if not all - expert programmers would advice against its use except under special circumstances.
Calling just free is alright - even better - in all but the borderline cases if the rest of your code is solid and well written.
Using
FreeAndNil all over the place is in mnsho the hallmark of a programmer that doesn't know what his code is doing.... < expect some flames by those type of programmers: they should be ignored.
FreeAndNil can hide REAL bugs....>
If you are a beginner, just call free, if your code subsequently crashes, you made a mistake.
The second proposal is wrong altogether it works but has no reference so you can not actually use it because you don't know where it is?
It works in combination with the with statement, though....
{$mode objfpc}
begin
with TObject.Create do
try
writeln(Classname);
finally
free;
end;
end.code]