want to confirm: gc will not free a non-gc-allocated field of a gc-allocated object?

Guillaume Piolat first.last at gmail.com
Mon Jun 6 22:24:45 UTC 2022


On Monday, 6 June 2022 at 22:18:08 UTC, mw wrote:
> So when `obj` is cleanup by the GC, obj.data won't be freed by 
> the GC: because the `data` is non-gc-allocated (and it's 
> allocated on the non-gc heap), the GC scanner will just skip 
> that field during a collection scan. Is this understanding 
> correct?

My understanding is that while scanning, the GC will see the 
data.ptr pointer, but will not scan the area it points to since 
it's not in a GC range (the runtime can distinguish managed 
pointer and other pointers).

After scanning, when obj is non-reachable, the GC will destroy it 
but that won't lead to a reclaim of data.ptr since it knows it 
doesn't own that.



More information about the Digitalmars-d-learn mailing list