On Wednesday, 21 January 2015 at 20:32:14 UTC, Steven Schveighoffer wrote:
Actually there's nothing on the documentation about class destructors [1] that warns about that specific issue of the current (and default) GC.

[1] http://dlang.org/class.html#destructors


I think the docs are in need of updating there. It's not meant to be a secret that you cannot allocate inside a GC collection. I'll try to put together a PR.

Please do!

On Thursday, 22 January 2015 at 14:07:31 UTC, Steven Schveighoffer wrote:
In the vast majority of cases, nobody adds a dtor, or they use dtors for their intended purpose (deallocating non-GC resources) and everything works fine. And the runtime catches any slips with an appropriate handling (abort instead of corrupt memory).

While you're writing that PR, would you clarify that "The destructor is expected to release any resources held by the object." means ***non-GC resources*** and that `new` will abort?

Also would you be so kind as to make a bolder warning that member refs to GC objects may be invalid? That's nasty and unexpected! (Java finalizers don't work like that.) [Nulling them out would be nicer for debugging...]

"This means that destructors cannot reference sub objects. This rule does not apply to auto objects or objects deleted with the DeleteExpression, as the destructor is not being run by the garbage collector, meaning all references are valid."

That wording contradicts the previous paragraph about "the delete expression ... [calls] ... the garbage collector calls the destructor immediately". Maybe something like "...not being run in a garbage collection..." would be better.

Reply via email to