June 07, 2022
On 07.06.22 11:00, max haughton wrote:
> On Tuesday, 7 June 2022 at 08:56:29 UTC, ag0aep6g wrote:
[...]
>> That wasn't mw's question.
> 
> I also answered this in my original one IIRC.

You didn't.
June 07, 2022
On Tuesday, 7 June 2022 at 09:12:25 UTC, ag0aep6g wrote:
> On 07.06.22 11:00, max haughton wrote:
>> On Tuesday, 7 June 2022 at 08:56:29 UTC, ag0aep6g wrote:
> [...]
>>> That wasn't mw's question.
>> 
>> I also answered this in my original one IIRC.
>
> You didn't.

Ok I must have assumed it was obvious it wouldn't free it.
June 07, 2022

On 6/6/22 6:18 PM, mw wrote:

>

Hi,

Suppose I have this code:

class GCAllocated {
   float[] data;

   this() {
     // non-gc-allocated field
     this.data = cast(float[])(core.stdc.stdlib.malloc(nBytes)[0 .. nBytes]);
   }
}

void foo() {
   auto obj = new GCAllocated();  // gc-allocated owning object
   ...
}

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?

Others have given answers on this, but I just want to clarify -- the GC does not use any type information to scan for pointers. The default GC has one bit to tell it whether a block contains pointers or not (if true, it will treat every word as if it were a pointer), and it does not understand array references, just pointers. The precise GC has a bitmap of which words in the block are pointers, and it also does not understand array references.

So you are safe, it will see the pointer inside the array reference, and see that it doesn't point at GC memory, so nothing further will be done.

-Steve

June 07, 2022

On Tuesday, 7 June 2022 at 13:56:23 UTC, Steven Schveighoffer wrote:

>

So you are safe, it will see the pointer inside the array reference, and see that it doesn't point at GC memory, so nothing further will be done.

Thanks for the detailed explanation, and everyone who has replied.

1 2
Next ›   Last »