Note that there are some explanatory texts on larger screens.

plurals
  1. PODelphi application leaking AnsiStrings
    primarykey
    data
    text
    <p>According to FastMM4, the Delphi program I'm working on at the moment is leaking a lot strings. AnsiStrings to be precise:</p> <p><img src="https://i.stack.imgur.com/287c9.png" alt="enter image description here"></p> <p>The application (<a href="http://sourceforge.net/projects/orwelldevcpp/" rel="noreferrer">http://sourceforge.net/projects/orwelldevcpp/</a>) 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.</p> <p><strong>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?</strong></p> <p>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)?</p> <p>I did manage to track a few leaks down by random commenting and seeing what would happen to the counts. Here's an example:</p> <pre><code>// 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! </code></pre> <p>Here's another example of a leak:</p> <pre><code>// 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!? </code></pre> <p>There are quite a bunch of string leak questions here, but none really clarify <strong>what patterns one should look for</strong>. Google doesn't provide either.</p> <p><strong>Edit: so, I have to look for passed constants. But why?</strong></p> <p><strong>So ehm, any ideas?</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload