On 21/09/16 11:00, Martin wrote:
On 21/09/2016 09:05, Mark Morgan Lloyd wrote:

Presumably this would be an assertion that something is assigned. A
related test is that an object is a specific subtype before using it
as such

  Assert(PageControl1.ActivePage.Controls[0] is TSynEdit);
  syn := TSynEdit(PageControl1.ActivePage.Controls[0]);

The problem is that even a test like that would NOT catch all cases.

Assert(syn is TSynEdit);

In this case, it is very likely that "syn is TSynEdit" still returns
true. (no assertion thrown)

Absolutely. But as you say later, anybody who doesn't use FreeAndNil() is asking for trouble.

Simply because "syn.destroy;" does not wipe the memory clean. (depending
on mem manager)

Using -gh
And (optionally) setting the environment HEAPTRC="keepreleased" (that is
for debugging only)
will help.

On top of that you can use -CR

Also search suspected code for every "destroy" or "free" and, replace
with FreeAndNil(var) if possible.

[From elsewhere a few years ago, somebody's wife looked over his shoulder and saw his Delphi code full of Create and Destroy calls. "Bit violent isn't it?" she remarked.]

Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org

Reply via email to