Mega Code Archive

 
Categories / Delphi / System
 

Measure memory leaks

Title: Measure memory leaks Question: How To Measure Memory Leaks Within block of Code ? Answer: How To Measure Memory Leaks Within block of Code the idea is just to calculate the differrent of allocated memory between start of code block and the end of code block using AllocMemSize global variable var Point1,Point2:Integer; IsLeak:Boolean; MyObject:TMyObject; begin Point1:=AllocMemSize; //Hold Allocated Memory size //Do something here within you code //like creating some objects //And allocating blocks of memory MyObject:=TMyObject.Create; . . . . . MyObject.Free; Point2:=AllocMemSize-Point1; //Get the differrent of //allocated memory size //between two Points of code if Point20 then ShowMessage('We have ' + IntToStr(Point2)+' as memory leak ') end;