Configuring the Garbage Collector
cam-bam
cam-stand at gmail.com
Fri Mar 14 17:09:59 UTC 2025
On Friday, 14 March 2025 at 14:59:50 UTC, Ogion wrote:
> 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.
Thank you. So just to clarify if I use the disable:1 option and
append to an array using the "~=" option this still will not
class garbage collection unless I implicitly say GC.collect()?
Thats pretty cool. furtrhermore, If I don't call GC.collect() I
would assume I would have to sort of free this memory manually
without running leaks
More information about the Digitalmars-d-learn
mailing list