IIRC, ref counting is at least more deterministic than traditional GC because it only runs when you destruct the object (it goes out scope, object gets reassigned whatnot).
In Comparison, traditional GCs like JVM runs on a background thread, it's hard to determine when they run and generally blocks the whole program while collecting (stop-the-world).
So at least they are a little better in that regard?
I can’t speak of Nim’s implementation but reference counting can block the whole program as large object graphs have to decrement their counts. But you are right it is more deterministic.
Javas modern GCs also have extremely low pauses. ZGC is effectively pauseless, you’re likely to experience kernel jitter/traps that last longer than a ZGC pause.
Does it suffer from the same trap as Dlang, in that their GC is also optional, but you lose the many of the conveniences from the standard library if you forgo completely with it?
ref counting is only performed if you use `ref` types, e.g.
type
RefObj = ref object
foo: string
bar: int
ValueObj = object
foo: string
bar: int
`RefObj` is ref counted equivalent to a shared_ptr in C++ land (non-atomic counter unless using --mm:atomicArc or Nim3/Nimony has this as a default I believe). `ValueObj` is equivalent to struct in C, C++, etc.
Nim has opt-in RC using the `ref` keyword; the default is stack-managed single-owner lifetimes, including for heap types. Passing is borrowing by default, while moving must be explicit; the vice-versa to Rust's approach. Data is technically cleaned up by the RC's procedures, but the destroy hooks are always called at the end of scope. And like I said, `ref` or `ptr` short-circuits that.
https://nim-lang.org/docs/mm.html