You free the querry and expect the fields property to stay alive ?
Querry := TZReadOnlyQuery.Create(nil); with Querry do begin ... Result := Fields; ... Free; end;
It seems to me it's true. The solution for example:
http://stackoverflow.com/questions/16846686/memory-leaks-when-returning-tfields-from-a-function (http://stackoverflow.com/questions/16846686/memory-leaks-when-returning-tfields-from-a-function)
And the way I call it:afaik that still gives you memory leakage for the query ?
var database: tmydb; tempresult: TFields; begin database:= tmydb.Create; tempresult:=database.query('SELECT * FROM testtable;').Fields; showmessage('Items found in testtable: ' + inttostr(tempresult.Count)); database.free; end;
Good point molly, I recompile using -gh and yup memory leak.Thanks for checking and reporting back.
... but if I have to choice between using unnecessary memory or a memory leak, I choice the unnecessary memory :-\Memory leaks are poison for apps, especially when they need to run 24/7. So, it is a wise decision ;D
ps: Big thank you for informing me about heaptrc. I now have to recompile bunch of my tools and I have the feeling few of them will make me cry ;)You're most welcome. It of course depends a little on your coding skills how happy you're going to be with that :P
Thank you titya. Work like a charme.
My code can look complicate when you don't know what I am aiming for. 3 softwares will use my dbclass.pas.