All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.delphi.rules.community-delphi.DestructorWithoutInherited.html Maven / Gradle / Ivy

There is a newer version: 1.12.1
Show newest version

Why is this an issue?

When objects are freed, the Destroy destructor method is called. Destroy must be an override (or virtual) method.

All classes inherit from TObject, which declares a virtual Destroy method, and should override this method to provide their own implementation.

To ensure that ancestor class destructors are also called, inherited should be called at the end of the destructor. Not doing so may cause the object to be only partially deinitialized.

How to fix it

Add an inherited call to the end of the destructor:

destructor TMyObj.Destroy;
begin
  FreeAndNil(FObj);
end;
destructor TMyObj.Destroy;
begin
  FreeAndNil(FObj);
  inherited;
end;

Resources





© 2015 - 2024 Weber Informatics LLC | Privacy Policy