The GC (agian)

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Tue Nov 23 09:45:44 UTC 2021


On Tuesday, 23 November 2021 at 07:14:17 UTC, bauss wrote:
> The GC doesn't work by scanning memory and figuring out whether 
> a block of memory is GC allocated or not.

I understand what you mean, but it has to, since D does not 
distinguish between GC pointers and non-GC pointers. It only 
distinguishes between GC and non GC memory (address ranges).

> The GC works by having a set of nodes that it scans through and 
> checks whether they have any references pointing to them.

More the opposite. It traverses the connected live graph by 
following outgoing pointers from nodes that are known to be live. 
If you have many nodes with pointers then that takes a lot of 
time.

With the current setup you might have to traverse a large 
subgraph that has no GC nodes in it.

If something is reachable from one of the GC roots it will have 
to scan it, just in case there might be some GC node deep down in 
the subgraph.

This is easy to mess up in larger programs, obviously.

```@nogc``` is just an escape hatch, it does not help with 
modelling issues or memory management issues.



More information about the Digitalmars-d mailing list