According to FastMM4, the Delphi program I'm working on at the moment is leaking a lot strings. AnsiStrings to be precise:
The application (http://sourceforge.net/projects/orwelldevcpp/) used to leak a lot more other data types, but FastMM4 could report where the instance was created, so I managed to fix that. The strange thing is that FastMM4 doesn't report locations of these leaks at all.
Edit: it seems it does after all, see answers for the fix. Anyways, the question still stands: how in the world am I leaking these things?
So, ehm, unfortunately, I've got no idea what to look for. I mean, if these things go out of scope, they should be automatically freed right (even though they're on the heap)?
I did manage to track a few leaks down by random commenting and seeing what would happen to the counts. Here's an example:
// simply passing it a constant creates a leak...
MainForm.UpdateSplash('Creating extra dialogs...');
procedure TMainForm.UpdateSplash(const text : AnsiString);
begin
if not devData.NoSplashScreen then // even if this branch is NOT taken
SplashForm.Statusbar.SimpleText := 'blablabla' + text;
end;
// And even if the function call itself is placed within a NOT taken branch!
Here's another example of a leak:
// Passing this constants produces leaks...
procedure TCodeInsList.AddItemByValues(const a, b, c: AnsiString;...);
var
assembleditem : PCodeIns;
begin
new(assembleditem);
assembleditem^.Caption:=a;
assembleditem^.Line:=b;
assembleditem^.Desc:=c;
...
fList.Add(assembleditem);
end;
// ... even when calling this on WM_DESTROY!
destructor TCodeInsList.Destroy;
var
I: integer;
begin
for I := 0 to fList.Count - 1 do
Dispose(fList[I]);
fList.Free;
inherited Destroy;
end;
// produces leaks!?
There are quite a bunch of string leak questions here, but none really clarify what patterns one should look for. Google doesn't provide either.
Edit: so, I have to look for passed constants. But why?
So ehm, any ideas?