Garbage Collectors

Steven Schveighoffer schveiguy at gmail.com
Wed Jul 19 13:39:11 UTC 2023


On 7/19/23 3:24 AM, IchorDev wrote:
> So, D’s default garbage collector is the one named “conservative” in 
> DRuntime…
> I see there’s also “manual” which doesn’t actually function as a GC, 
> which is interesting.
> Nothing says what ProtoGC is… so I guess it’s useless.
> Has anyone ever published any custom GCs? A search through the dub 
> package registry yielded nothing. How hard would it be to port (for 
> instance) a Java GC to D’s interface?

To answer the question about ProtoGC, it is a stub GC which will create 
the appropriate GC (based on runtime flags) when the first function that 
requires actually using the GC is called. It is actually the default GC.

This was introduced to implement more pay-as-you-go runtime features. If 
you don't use the GC, no GC is created.

If I recall correctly, you must attempt to allocate using the GC for the 
ProtoGC to do its thing. Everything else is just simple stubs (e.g. 
ProtoGC.free does nothing, since it can never allocate memory)

-Steve


More information about the Digitalmars-d-learn mailing list