Understanding the GC
FG
home at fgda.pl
Fri Feb 1 09:41:47 PST 2013
On 2013-02-01 16:37, Steven Schveighoffer wrote:
> Actually, that's a different problem. File is a struct, and structs do NOT have
> their destructor run by the GC. Only Objects do.
>
> This is a GC limitation, since structs do not contain a pointer to their
> typeinfo like classes do, and there is no provision for storing a pointer to the
> typeinfo of a block. It could be fixed by a more precise GC. AIUI, we have
> something like that coming, but I've been hearing that for more than a year ;)
So currently the only way to make a struct's destructor work when the struct is
on the heap is to encapsulate that struct in a class?
I have tested the following:
struct A { ... }
class C { A a; ... }
A a = A(); // OK
A *b = new A(); // BAD, no finalization
C c = new C(); // OK, a's destructor will be called
More information about the Digitalmars-d-learn
mailing list