Don't expect class destructors to be called at all by the GC
Neia Neutuladh
neia at ikeran.org
Fri Dec 22 05:51:23 UTC 2017
On Thursday, 21 December 2017 at 18:20:19 UTC, H. S. Teoh wrote:
> Even calling GC.collect directly did not guarantee the DB
> handle was closed at the right time. This may have been a bug
> in my code that left dangling references to it, or perhaps the
> array of Database handles was still scanned through by the GC
> even though the only remaining array slice has a shorter
> length. Whatever the reason was, it left me with the very
> unpleasant prospect of silently accumulating file descriptor
> leaks.
Last I checked, the GC doesn't understand arrays. It only
understands "segment of memory that might contain pointers" and
"segment of memory that doesn't contain pointers". You might have
gotten better results if you had nulled out the reference in the
array.
Of course, that relies on not having any remaining references on
the stack or in registers, neither of which is easy to guarantee.
More information about the Digitalmars-d-learn
mailing list