January 11, 2024
https://issues.dlang.org/show_bug.cgi?id=24331

          Issue ID: 24331
           Summary: @nogc and GC.disable() are often confused
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dlang.org
          Assignee: nobody@puremagic.com
          Reporter: bugzilla@digitalmars.com

Adam Wilson writes:

@nogc works just fine. We recently spent a good chunk of time in Discord educating a newbie on what it actually does.

What @nogc is specified to do: Prevent GC allocations from occurring. Fantastic. What people actually do with @nogc: Use it to selectively disable the GC without using GC.disable().

The reason for this stems from a side-effect of how the current GC operates. Because allocations are the trigger for collections, by preventing allocations, collections are also prevented. And what people really want to do is disable collections because they don't like the collection pauses. They don't actually care about the allocations per se because that is generally as fast as a malloc and they are going to have to allocate at some point anyways.

So @nogc works exactly as specified, but because of an unspecified implementation side-effect, that is not guaranteed to hold true in the future, the @nogc crowd writes their code as if @nogc does something else entirely. And we end up here in this thread.

--