Garbage collector collects live objects

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Dec 9 12:54:58 PST 2014


On 12/9/14 3:18 PM, Ali Çehreli wrote:
> On 12/09/2014 11:56 AM, Steven Schveighoffer wrote:
>
>  >> i checked attributes for GC block holding this array:
>  >>
>  >> ```
>  >> FINALIZE NO_SCAN NO_MOVE APPENDABLE NO_INTERIOR
>  >> ```
>  >>
>  >
>  > That does not sound right at all. No block should ever have both
>  > FINALIZE (reserved for objects only) and APPENDABLE (reserved for arrays
>  > only).
>
> FINALIZE and APPENDABLE together sounds like "an array that holds class
> objects."
>
> I think I get it as I write this: Do we mean that the array should
> always hold class references and the class objects should live on other
> blocks? If so, the memory block for the objects can be marked as
> FINALIZE?

Yes, that's exactly right. A class is never allocated "inline" inside 
another object or an array.

> What block should be APPENDABLE?

The array of class references can be APPENDABLE.

> Of course, this may be all in the documentation but I can't understand
> it. ;) Here is what is says for FINALIZE: "Finalize the data in this
> block on collect." (I will study that part a little more. :p)
>
>    http://dlang.org/phobos/core_memory.html#.GC.BlkAttr.FINALIZE

In truth, the code expects the block then to have a ClassInfo pointer at 
the beginning of the block.

See here:

https://github.com/D-Programming-Language/druntime/blob/master/src/rt/lifetime.d#L1225

-Steve


More information about the Digitalmars-d-learn mailing list