On Sunday, March 31, 2013 22:15:14 monarch_dodra wrote: > Currently, the GC only finalizes classes. structs/arrays, > allocated via the GC, are not finalized. > > I don't have much experience with GC, so ... > > Question: Is this the intended behavior, or is it currently only > a limitation? WIll we ever have a GC that is capable of > finalizing structs/arrays? > > Question2: If the idea is that the GC *should* finalize, then how > are we supposed to specify the finalizer to the GC when we > allocate via GC.malloc ? There is apparently a > GC.BLKAttr.FINALIZE, but how do you specify *how* to finalize...? > > My "big" worry is that when we finally have a GC that can handle > built-in array finalization, all our code that manually manages > memory (for example: "std.array.array") will become buggy... > > Thoughts? Insight?
It's my understanding that structs don't get finalized, because the type information isn't there at runtime to do it. I don't know if that can be gotten around or not, but my guess is that it's a permanent restriction unless we start putting invisible member variables in structs which have that information. I don't know though. Classes, on the other hand, hold information on their actual types at runtime, so the information is there to finalize them. But regardless, there is _no_ guarantee that _anything_ on the GC heap will ever be finalized, so any program which relies on anything on the GC heap being finalized is buggy by definition, and I don't expect that to ever change. - Jonathan M Davis
