On Sunday, 31 March 2013 at 20:15:15 UTC, 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?
This is intended bahaviour. Struct objects suposed to be
lightweight and map (except some cases) to C structs ABI. It
would be complicated to make heap structs to be GC collectible
taking into account that object can be moved without hacking
current struct ABI layout.
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...?
I didn't hear about the consensus that heap structs should be
collected by GC.
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?
This is even more unlikely - to break tonns of code for the sake
of making heap structs collected.
If you are interested in solution for this problem, then you can
probably try luck in ctors/dtors/overload operators, using some
reference counting algorithms or hijack context pointer of nested
structs for the purpose of keeping runtime info. I doubt that it
can be reliably implemented and worth using.