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

max haughton maxhaton at gmail.com
Tue Jun 7 01:02:35 UTC 2022


On Tuesday, 7 June 2022 at 00:40:56 UTC, ag0aep6g wrote:
> On 07.06.22 00:22, max haughton wrote:
>> float[] doesn't contain pointers, so the GC won't do anything 
>> to or with it.
>
> wat
>
> float[] is a pointer (plus a length). The GC will deal with it 
> like any other pointer.

I'm talking about the data in the array.

void[] might contain pointers, float[] does not so it won't be 
scanned. Or at least shouldn't be...

This is why you shouldn't use void[] for everything if you can 
help it.

```
void main()
{
     import std.stdio;
     auto voidArray = typeid(void[]);
     auto floatArray = typeid(float[]);
     writeln(voidArray.next.flags() & 1 );
     writeln(floatArray.next.flags() & 1);
}
```


More information about the Digitalmars-d-learn mailing list