How can I track the count of a certain class in memory in Delphi 7, without adding a static counting member in the class.
For the purpose of tracking the program performance.
Thank you in advanced.
How can I track the count of a certain class in memory in Delphi
Share
You can hook the NewInstance and FreeInstance methods in the class VMT:
Include this unit in any
usesclause of your program and now theBitBtnInstanceCounterwill track the count ofTBitBtninstances.Edit: if it is possible that several threads simultaneously create objects of the tracked class, it is necessary to use interlocked access to modify the counter variable. Beware that third-party components could silently use threads, so it’s safer to not define the
SINGLE_THREADsymbol.