Sometime, when I close my app I have this error :
---------------------------
Unexpected Memory Leak
---------------------------
An unexpected memory leak has occurred. The unexpected small block leaks are:
21 - 28 bytes: TGradientPoints x 2, TGradientPoint x 4, Unknown x 2
29 - 36 bytes: TD2DBitmapHandle x 1, TGradient x 2, TBitmapImage x 3, TBrushBitmap x 2
37 - 44 bytes: TFont x 1, TList<System.Classes.TCollectionItem> x 2, TBrushResource x 2, TPosition x 12
45 - 52 bytes: TBitmap x 3, TObjectList<FMX.Graphics.TCanvasSaveState> x 1, UnicodeString x 1
53 - 60 bytes: TBrush x 1
61 - 68 bytes: Unknown x 1
69 - 76 bytes: TTransform x 2
77 - 84 bytes: TStrokeBrush x 1
237 - 252 bytes: TCanvasD2D x 1
---------------------------
OK
---------------------------
The problem is that I can't find out from where those memory leaks come from and as this exception raise very rarely it's very hard to debug. :(
Is their any good way to find the root cause of memory leak?
CodePudding user response:
The only solution is to identify the classes where you create object instances and find and/or debug the point in code where you should deallocate them.
I don't have you code under my hands, but I could deduce from your leaks report that TFont
, TBrush
and TBitmap
may belong to a TForm
instantied by hand (and not by Application.CreateForm
) in your code and not freed.
The latter one should be a good starting point...
CodePudding user response:
The option is to use FASTMM5 instead of the default FastMM4 included in Delphi. with FastMM5 we can do :
if FastMM_LoadDebugSupportLibrary then
begin
FastMM_EnterDebugMode;
FastMM_MessageBoxEvents := FastMM_MessageBoxEvents [mmetUnexpectedMemoryLeakDetail];
end;
Then at shunt down we have the exact stack trace of the memory leak.