Intercept constructors and destructors of all objects in Delphi

Asked

Viewed 51 times

5

I use a feature on my system where some users may have access to scripts in Pascal Object and can customize some rules.

This is generating a certain problem of Memory Leak, because just as a developer can forget to destroy an object the user can do the same in this feature, so I’m needing to create a control of Memory Leak very simple and light, where the user will know that created an object but did not destroy it.

The problem I’m facing is intercepting the TComponent in the constructor and destructor to monitor the created and destroyed objects.

I tried my hardest:

TComponent = class helper for System.Classes.TComponent
protected
  constructor Create;
  destructor Destroy; // Aqui ocorre um erro ao compilar;
end;

or

TComponent = class(System.Classes.TComponent)
protected
  constructor Create; override;
  destructor Destroy; override;
end;

In this case it does not always pass, because I have to put in use of all Units.

Does anyone have any solution or hint?

Thank you in advance.

  • 1

    The ideal would be to create a base class of the Generic type with Interface implementation. This way Delphi itself would take care of the demand. In Delphi ARC controls the Leak memory alone, but only for Interface.

  • Thank you so much for the tip. I will do some research and if successful, I will post here. But if anyone else wishes to speak, I will be grateful.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.