By a closer look at the application we can see that there are three different test procedures to simulate memory issues:
Memory Leaks
procedureTMainForm.UniButton1Click(Sender: TObject);var P : PInt64;begin // Simulate memory leak: // We create a memory instance for Int64, but we don't free it (memory leak)New(P); // Below call will terminate the standalone server, so we can see FastMM leak error message immediately. // This is done for demonstration purpose only. // Never call "UniServerInstance.Terminate" in your production code // Alternatively, you can comment below line and exit from application manually. UniServerInstance.Terminate;end;
In the above event we try to simulate a memory leak by creating a PInt64 instance. Since memory leaks are only reported upon exit we terminate the application immediately to see the error message box:
clip0361
At the same time the memory leak will be logged to the FastMM log file which will be created under the same folder.
The above log indicates that the memory object was allocated in code line 61:
clip0364
The block was previously freed by thread 0x5164, and the stack trace (return addresses) at the time was:
Allocated memory is disposed at line 62.
Please note that FastMM is unable to find the exact line of code where memory is altered. FastMM can only detect and report that a memory location is altered after it has been freed and reallocated.
A memory block has been leaked. The size is: 12
This block was allocated by thread 0x7580, and the stack trace (return addresses) at the time was:
00406C36 [System.pas][System][GetMem][4189]
0088EC1A [Main.pas][Main][TMainForm.UniButton1Click$qqrp14System.TObject][46]
0078BA54 [uniGUIClasses.pas][uniGUIClasses][TUniControl.DoClick$qqrv][3694]
007EED2D [uniButton.pas][uniButton][TUniCustomButton.DoClick$qqrv][582]
007EE16C [uniButton.pas][uniButton][TUniCustomButton.ClickHandler$qqrp20Extpascal.TExtObject20System.UnicodeStringp23Uniguitypes.TUniStrings][358]
0075DB21 [uniGUIJSInterface.pas][uniGUIJSInterface][TUniJSHelper.HandleEvent$qqrx20System.UnicodeStringp20Extpascal.TExtObjectp23Uniguitypes.TUniStrings][1115]
0078DA9A [uniGUIClasses.pas][uniGUIClasses][TUniControl.HandleEventIntercept$qqrp20Extpascal.TExtObjectx20System.UnicodeString][4388]
0070EAF1 [ExtPascal.pas][ExtPascal][TExtThread.ObjectHandler$qqrp20Extpascal.TExtObjectx20System.UnicodeString][805]
007C0141 [uniGUIApplication.pas][uniGUIApplication][TUniGUISession.ObjectHandler$qqrp20Extpascal.TExtObjectx20System.UnicodeString][3648]
006FAA70 [ExtHTTPServer.pas][ExtHTTPServer][TIdExtSession.GetQuery$qqrx20System.UnicodeString][426]
0070EC6C [ExtPascal.pas][ExtPascal][TExtThread.HandleEvent$qqrv][828]
The block is currently used for an objectofclass: Unknown
The allocation number is: 35353
procedure TMainForm.UniButton2Click(Sender: TObject);
var
P : PInt64;
begin
// Simulate memory corruption:
// We create a memory instance for Int64 and immediately dispose it
New(P);
Dispose(P);
// Now we try to access the memory location which is already freed.
// FastMM will catch it and will display an error message
P^ := 0;
end;
FastMM has detected an error during a GetMem operation. FastMM detected that a block has been modified after being freed.
Modified byte offsets (and lengths): 0(3), 4(4)
The previous block size was: 8
This block was previously allocated by thread 0x5164, and the stack trace (return addresses) at the time was:
00406C36 [System.pas][System][GetMem][4189]
0088EC42 [Main.pas][Main][TMainForm.UniButton2Click$qqrp14System.TObject][61]
0078BA54 [uniGUIClasses.pas][uniGUIClasses][TUniControl.DoClick$qqrv][3694]
007EED2D [uniButton.pas][uniButton][TUniCustomButton.DoClick$qqrv][582]
007EE16C [uniButton.pas][uniButton][TUniCustomButton.ClickHandler$qqrp20Extpascal.TExtObject20System.UnicodeStringp23Uniguitypes.TUniStrings][358]
0075DB21 [uniGUIJSInterface.pas][uniGUIJSInterface][TUniJSHelper.HandleEvent$qqrx20System.UnicodeStringp20Extpascal.TExtObjectp23Uniguitypes.TUniStrings][1115]
0078DA9A [uniGUIClasses.pas][uniGUIClasses][TUniControl.HandleEventIntercept$qqrp20Extpascal.TExtObjectx20System.UnicodeString][4388]
0070EAF1 [ExtPascal.pas][ExtPascal][TExtThread.ObjectHandler$qqrp20Extpascal.TExtObjectx20System.UnicodeString][805]
007C0141 [uniGUIApplication.pas][uniGUIApplication][TUniGUISession.ObjectHandler$qqrp20Extpascal.TExtObjectx20System.UnicodeString][3648]
006FAA70 [ExtHTTPServer.pas][ExtHTTPServer][TIdExtSession.GetQuery$qqrx20System.UnicodeString][426]
0070EC6C [ExtPascal.pas][ExtPascal][TExtThread.HandleEvent$qqrv][828]