Jacek Laskowski 57 Posted April 28, 2020 Simple example: program leak; {$APPTYPE CONSOLE} {$R *.res} uses FastMM4, System.SysUtils; type TRx = record s : string; v : Variant; end; TAx = TArray<TRx>; procedure Test; var lA : TAx; begin SetLength(lA, 3); lA[0].s := 'test2'; lA[0].v := 888; lA[1].s := 'test1'; lA[1].v := Now; lA[2].s := 'test3'; lA[2].v := 'str'; end; begin try Test; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end. When I don't assign TDateTime to a Variant field, the debugger shows the array and all records correctly, as in the picture on the left. And there is no leakage. But when I assign TDateTime type to Variant field, as on the right side of the picture, the debugger does not show "plus" in hint window and I get a memory leak at the end. What is wrong with this code? Share this post Link to post
aehimself 396 Posted April 28, 2020 Do you get the same leak report if you don't debug the code, just let it to run? It should not be the case, but try to call VarClear on the variant before exiting, and finalizing the array. Share this post Link to post
Jacek Laskowski 57 Posted April 29, 2020 In fact, when I'm not debuging, there is no leak. But is it an IDE error to show the record array (without the record expansion plus) in a hint debugger? Because I was afraid it was a problem in my record and array memory management. I do some tricks there. Share this post Link to post
David Heffernan 2345 Posted April 29, 2020 When the debugger evaluates some variables to display values in the debugger it often leaks memory. This is a defect with the debugger. The code here does not leak. Any reported leaks are due the debugger. I see this very often with property getter functions that return strings. The debugger calls the function, creating a new string. But then the debugger fails to destroy the string. Leak. Share this post Link to post
David Heffernan 2345 Posted April 29, 2020 11 hours ago, aehimself said: Do you get the same leak report if you don't debug the code, just let it to run? It should not be the case, but try to call VarClear on the variant before exiting, and finalizing the array. Not needed. Really not a great idea to suggest needless actions with no basis in fact. Just spreads FUD. Share this post Link to post