John, my too-well seasoned "take" on this sort of situation is that: "there is
almost-certainly
nothing wrong with" the particular piece of code that you're looking at. It is, as you well know, "absolutely
certain that 'the bug is
not here."
Nope ... your assessment is
(unfortunately) entirely correct: something,
somewhere, is "absolutely trashing memory," well
before the point of failure. It could be "anywhere,
anytime." But I'll bet my bottom dollar that: [i](a)/i] it will be related to freeing things, and
(b) if this application ever was stable, it will be related to a change made since that time.
Let me now relate to you my "$10,000
(hard dollars) tale of woe." It looked like this:
Code:
a.free;
b.free;
a := nil;
b := nil;
(in Delphi ... in code that I had purchased ...) and the solution looked like this:
Code:
a.free;
a := nil;
b.free;
b := nil;
The root cause of this error was
many source-files away, in code that was "thoroughly tested."
(Really!) I know perfectly well that you
do, of course, see the well-hidden problem . . . as did I . . . as did the vendor that I could not in any good conscience sue . . . too late,
$$much$$ too late.
That is what you are dealing with now. And I would be delighted to prescribe that any sort of electric tool will help you find it.
(Sometimes, computer-programming for-a-living
s-u-c-k-s ...)