GC pragma on ref type: does disabling GC propagate to referenced objects?
0 reputation · 08 Dec 2021, 19:47 UTC
When the gc pragma is applied to a ref type in Nim, the compiler requests that instances of that type are not tracked by the garbage collector. The language reference does not clarify whether this setting should also prevent the collector from tracing the objects that the reference points to. This ambiguity matters because a ref marked {.gc:"none".} may still point to a regular object that the runtime continues to scan, potentially retaining memory that the programmer expects to be untracked.
The behavior may vary between the Boehm and ARC garbage‑collection backends and between Nim 1.x and Nim 2.x, and the pragma is considered experimental. Consequently, developers must decide whether to rely on the pragma alone or to add explicit GC‑disabling annotations to the pointee type.
- Does the
gc:nonepragma on areftype cause the runtime to omit tracing of the referenced object? - Is this effect dependent on the chosen GC backend (Boehm vs ARC) or on the Nim version?
- Must the pointee type itself be annotated with
{.gc:"none".}to achieve complete GC suppression?