Virtual method interception – introduced with Delphi XE – can be used to ‘proxify’ methods so that custom code can be executed before and after the original method.
Could this also be used to keep a count of all object instances in a Delphi application, by proxyfying the virtual methods TObject.AfterConstruction and TObject.BeforeDestruction?
If yes, this could be a simple way to analyse FastMM4 memory allocation statistics at run time (using the InstanceSize property of objects and matching it against the allocated memory blocks).
Update: sorry for asking a question which was very easy to answer from the DocWiki information – I have read the linked article first and only skimmed the example code
No, that’s not going to work. From the documentation, with my emphasis:
The problem is that you need to get hold of each and every instance before you can proxify. But you are hoping to proxify in order to get hold of instances. So you are now caught in a chicken and egg scenario.