On Thursday, 24 May 2012 at 20:53:33 UTC, Tove wrote:
On Thursday, 24 May 2012 at 19:46:07 UTC, foobar wrote:
Looks to me like an issue with separation of concerns. I think
that dtors need to only provide deterministic management of
resources and not affect GC algorithms:
1. classes should *not* have dtors at all.
2. struct values should *not* be gc managed [*].
Why not simply set "BlkAttr.NO_SCAN" on ourselves if we need
certain resources in the destructor? Assuming we one day get
user defined attributes, it can be make quite simple...
Tested my idea... unfortunately it's broken...
GC.collect() while the program is running, is OK... so I was
hoping to add:
GC.disable() just before main() ends, but apparently this request
is ignored.
i.e. back to square 1, undefined collecting order once the
program exits.
import std.stdio;
import core.memory;
class Important
{
this()
{
us ~= this;
}
~this()
{
writeln("2");
}
private:
static Important[] us;
}
class CollectMe
{
Important resource;
this()
{
resource = new Important();
}
~this()
{
writeln("1");
clear(resource);
}
}
void main()
{
GC.setAttr(cast(void*)new CollectMe(), GC.BlkAttr.NO_SCAN);
GC.collect();
GC.disable();
writeln("3");
}