=== Memory management ===
Nim supports multiple memory management strategies, including the following:<ref>{{Cite web |title=Nim's Memory Management |url=https://nim-lang.org/docs/mm.html |access-date=20232024-0807-1728 |website=nim-lang.org}}</ref>
* <code>-- gcmm:arc</code> – Automatic [[reference counting]] (ARC) with [[move semantics]] optimizations, offers a shared heap. It offers fully deterministic performance for hard realtime systems.<ref>{{Cite web |title=Introduction to ARC/ORC in Nim |url=https://nim-lang.org/blog/2020/10/15/introduction-to-arc-orc-in-nim.html |access-date=2023-08-17 |website=Nim Programming Language |language=en}}</ref> Reference cycles may cause memory leaks: these may be dealt with by manually annotating <code>{.acyclic.}</code> pragmas or by using <code>-- gcmm:orc</code>. ▼
* <code>--gc:refc</code> – Standard deferred [[reference counting]] based [[Garbage collection (computer science)|garbage collector]] with a simple mark-and-sweep backup GC in order to collect cycles. Heaps are thread-local. ▼
* <code>-- gcmm:orc</code> – Same as <code>-- gcmm:arc</code> but adds a cycle collector (the "O") based on "trial deletion".<ref>{{Cite web |title=ORC - Vorsprung durch Algorithmen |url=https://nim-lang.org/blog/2020/12/08/introducing-orc.html |access-date=2023-08-17 |website=Nim Programming Language |language=en}}</ref> The cycle collector only analyzes types if they are potentially cyclic . ORC is the default memory management strategy. ▼
* <code>--gc:markAndSweep</code> – Simple [[Mark and sweep|mark-and-sweep]] based [[Garbage collection (computer science)|garbage collector]]. Heaps are thread-local.
* <code>--gcmm:boehmrefc</code> – Standard deferred [[Boehm garbagereference collector|Boehmcounting]] based [[Garbage collection (computer science)|garbage collector]], it offerswith a sharedsimple mark-and-sweep backup GC in order to collect cycles. Heaps are heapthread-local.
* <code>--gcmm:gomarkAndSweep</code> – Simple [[GoMark (programmingand language)sweep|Gomark-and-sweep]]'s based [[Garbage collection (computer science)|garbage collector]], useful for interoperability with [[Go (programming language)|Go]]. Offers aHeaps sharedare heapthread-local.
▲* <code>-- gcmm: refcboehm</code> – Standard deferred [[ referenceBoehm garbage countingcollector|Boehm]] based [[Garbage collection (computer science)|garbage collector]] , withit offers a simple mark-and-sweep backup GC in order to collect cycles. Heaps areshared thread-localheap.
▲* <code>--gc:arc</code> – Automatic [[reference counting]] (ARC) with [[move semantics]] optimizations, offers a shared heap. It offers fully deterministic performance for hard realtime systems.<ref>{{Cite web |title=Introduction to ARC/ORC in Nim |url=https://nim-lang.org/blog/2020/10/15/introduction-to-arc-orc-in-nim.html |access-date=2023-08-17 |website=Nim Programming Language |language=en}}</ref> Reference cycles may cause memory leaks: these may be dealt with by manually annotating <code>{.acyclic.}</code> pragmas or by using <code>--gc:orc</code>.
* <code>--mm:go</code> – [[Go (programming language)|Go]]'s [[Garbage collection (computer science)|garbage collector]], useful for interoperability with [[Go (programming language)|Go]]. Offers a shared heap.
▲* <code>--gc:orc</code> – Same as <code>--gc:arc</code> but adds a cycle collector (the "O") based on "trial deletion".<ref>{{Cite web |title=ORC - Vorsprung durch Algorithmen |url=https://nim-lang.org/blog/2020/12/08/introducing-orc.html |access-date=2023-08-17 |website=Nim Programming Language |language=en}}</ref> The cycle collector only analyzes types if they are potentially cyclic.
* <code>--gcmm:none</code> – No memory management strategy nor a [[Garbage collection (computer science)|garbage collector]]. Allocated memory is simply never freed, unless manually freed by the developer's code.
As of Nim 2.0, ORC is the default GC.<ref>{{Cite web |title=Nim v2.0 released |url=https://nim-lang.org/blog/2023/08/01/nim-v20-released.html |access-date=2023-08-17 |website=Nim Programming Language |language=en}}</ref>
|