Skip to content

Commit 0df0c5b

Browse files
WalterBrightdlang-bot
authored andcommitted
fix Issue 24331 - @nogc and GC.disable() are often confused
1 parent c53262f commit 0df0c5b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

spec/function.dd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3752,6 +3752,14 @@ $(H2 $(LNAME2 nogc-functions, No-GC Functions))
37523752
}
37533753
---
37543754

3755+
$(BEST_PRACTICE Since a function marked `@nogc` will not do any GC allocations,
3756+
that implies it will not cause any GC collections to run. However,
3757+
another thread may still allocate with the GC and trigger a collection.
3758+
The recommended way to prevent GC collections from being run is to call
3759+
$(LINK2 https://dlang.org/phobos/core_memory.html#GC.disable, core.memory.GC.disable())
3760+
instead. This will stop collections from being run in any thread until a corresponding
3761+
call to `core.memory.GC.enable()` is run. GC allocations can still be performed
3762+
when `GC.disable()` is in effect.)
37553763

37563764
$(H2 $(LNAME2 function-safety, Function Safety))
37573765

0 commit comments

Comments
 (0)