Memory leaks or am I doing something wrong?


Type

TDBEmailHistory = Class
    MyConnection: IDBConnection;
    DBManager : TDatabaseManager;
    ObjManager : TObjectManager;
    constructor Create;
    destructor Destroy; virtual;
End;

constructor TDBEmailHistory.Create;
begin
MyConnection := TSQLiteNativeConnectionAdapter.Create('../KMedEmail.SQLite3.db');
DBManager := TDatabaseManager.Create(MyConnection);
if not FileExists('email.SQLite3.db') then
    DBManager.BuildDatabase
else
    Assert(DBManager.ValidateDatabase,'DB Failed Validation');
ObjManager := TObjectManager.Create(MyConnection);
end;

destructor TDBEmailHistory.Destroy;
begin
ObjManager.Free;
DBManager.Free;
(MyConnection as TSQLiteNativeConnectionAdapter).Free;
end;

// Plain empty form. Just load it in the ide then click the red X. 100 - 200 small block memory
// leaks are reported depending on for loop iterations.

procedure TForm1.FormCreate(Sender: TObject);
Var
xDB : TDBEmailHistory;
I : Integer;
begin
ReportMemoryLeaksOnShutdown := True;
for I := 1 to 100 do begin
    xDB := TDBEmailHistory.Create;
    xDB.Free;
    end;
end;

Also, I am using Delphi XE5

One thing that looks out of place there - MyConnection is an interface so shouldn't need to be free'd. The scoping rules will take care of that when the xDB instance is free'd.

Initially I didn't free it but when I saw the memory leaks, maybe 50 small blocks all related to aurelius then I add that code. I will remove it.

Thanks.

This still doesn't work. FastMM4 reports multiples of 100 memory leaks using the exact code above. I might be inclined to overlook expanding memory leaks for the time being if this was for a utility but it is for a service that must run non-stop.

I did remove the call to free the interfaced object.

Any other ideas that I can try?

I can't account for what changed. I started a new project with just enough to reproduce the issue and it didn't do it. And then when I returned to the original project the problem disappeared there too. I hate this kind of indeterminate solution. lol. However, I now have a lot more confidence in Aurelius. It is easy to work with.



Thanks everyone for your suggestions and support. :-)