I think you are looking for GC_ref() and GC_unref() pair from system module. For Nim's ref values (managed pointers) applying GC_ref() blocks the Nim memory management system from freeing the data, and later GC_unref() allows it again.
- Managed references to unmanaged references? RodSteward
- Managed references to unmanaged references? Stefan_Salewski