Casting an object only to free it is superfluous. TObject.Free will always call the
correct destructor, regardless of the variable's type.
Also, because the Free method is on TObject, it is present on
all objects inheriting from TObject - no casting is needed to access it.
TMyObject(MyVar).Free; // Noncompliant (MyVar as TMyObject).Free; // Noncompliant FreeAndNil(TMyObject(MyVar)); // Noncompliant FreeAndNil(MyVar as TMyObject); // Noncompliant MyVar.Free; // Compliant FreeAndNil(MyVar); // Compliant
Remove the unnecessary cast:
TMyObject(MyVar).Free; FreeAndNil(TMyObject(MyVar));
MyVar.Free; FreeAndNil(MyVar);