I think following document and example code explain why your code cause error and would help you to find a way to fix it:
* <https://nim-lang.org/docs/destructors.html#the-dotcursor-annotation> Compile this code with `nim c -r --mm:orc test.nim`: type NodeObj = object left: Node right {.cursor.}: Node name: string Node = ref NodeObj proc `=destroy`(x: var NodeObj) = echo "destroy ", x.name proc main = var n0 = Node(name: "n0") r = Node(left: n0, right: n0, name: "r") n0 = nil echo "r.left = nil" r.left = nil echo "r.right = nil" r.right = nil echo "end of main" main() Run