clear() causes crash?
Denis Shelomovskij
verylonglogin.reg at gmail.com
Fri May 10 19:37:43 PDT 2013
30.04.2013 1:04, "Luís Marques" <luismarques at gmail.com>" пишет:
> This crashes in the last line of main:
>
> class A
> {
> void foo() {}
> }
>
> void main()
> {
> A a = new A();
> a.foo();
> clear(a);
> assert(a !is null);
> a.foo(); // crashes
> }
>
> As far as I understand from TDPL book, this should not crash, but it
> does (DMD64 v2.062, OS X). Am I misunderstanding clear()?
>
> BTW, why not make clear also change 'a' to null?
Ideally is should throw with pretty message but it isn't implemented.
See Issue 8139 - Make objects really disposable by addition of "Object
finalized" assertion [1].
IMO, also `destroy` (renamed `clear`) looks like the worst mistake in D
runtime and I'd recommend to not use it (or better recompile
druntime+phobos without it for your own use). See Issue 9139 - `destroy`
is dangerous and inconsistent [2]. Use
`unstd.lifetime.finalizeClassInstance` [3] and friends for user-defined
lifetime implementation to avoid serious problems.
[1] http://d.puremagic.com/issues/show_bug.cgi?id=8139
[2] http://d.puremagic.com/issues/show_bug.cgi?id=9139
[3]
http://denis-sh.github.io/phobos-additions/unstd.lifetime.html#finalizeClassInstance
--
Денис В. Шеломовский
Denis V. Shelomovskij
More information about the Digitalmars-d
mailing list