On Friday, 14 March 2025 at 09:14:38 UTC, cam-bam wrote:
What effect does the disable:1 option have on garbage collection?
It stops GC from running. Meaning, you can still allocate memory from GC heap and use all functionality that requires GC, but allocations will not trigger garbage collection (you can still run it manually with `GC.collect`).
if I wanted to avoid the garbage collector entirely would it be best to just use betterC or do manual memory management as suggested by the [blog](https://dlang.org/blog/2017/09/25/go-your-own-way-part-two-the-heap/)
BetterC is a subset of D with a reduced feature set. It removes all features that depend on DRuntime: not only GC but also classes, exceptions, RTTI etc. Phobos and D libraries are mostly incompatible with it. It’s meant for cases when you can’t use DRuntime, like if you’re targeting WebAssembly or some microcontroller.
Manual memory management doesn’t require disabling GC or writing in BetterC. Garbage collection can only be triggered when you allocate memory from the GC heap. But You can always use the good old `malloc` and `free`.
Probably, you don’t need to avoid GC in the entirety of your program. You can make the “hot” part of your code `@nogc` to make sure that you don’t accidentally use GC there, and freely use GC outside of it.