Questions about GC

H. S. Teoh hsteoh at qfbox.info
Mon Jun 22 23:56:15 UTC 2026


On Mon, Jun 22, 2026 at 11:37:56PM +0000, Thomas via Digitalmars-d-learn wrote:
> Hi, just a couple of questions about how the GC works
> 
> 1.
> 
> if you have an array that doesnt have any pointers like
> 
> ```
> struct Point { double x,y;}
> 
> Point[] points;
> ```
> 
> Does the GC still go through and scan them for pointers or does the
> compiler know that it doesn't have to?

Pretty sure such an array would have the NO_SCAN bit set, so the GC
won't waste time scanning it.  Only blocks that might contain pointers
will get scanned.


> 2.
> 
> if you have an array with a local scope
> 
> ```
> while(something)
> {
>    int[] xs;
> 
>    // do something
> 
> }  <-- does it return the memory here for 'xs' for reuse instantly
> since it knows it's unreachable or does it wait for a collection
> event?
> ```

It will wait for a collection event.

If you don't want that, you could explicitly reuse the array, or use a
static (stack-allocated) array.  Or skip the GC and call C's malloc /
free instead.


T

-- 
No! I'm not in denial!


More information about the Digitalmars-d-learn mailing list