Well Nim as a language is dumb, just like most language that relies on destructors like Rust 🙂. It's the user that decides when a ressource needs to be freed. I have never needed to worry about such "dependency tree" because when the ressource lifetime is complicated the library has utilities to track when you can free it anyways. On the Nim side what would be done is `importc` the ressource which is probably a `pointer`, wrap it with a proper Nim object so you can define a `=destroy` which checks whether the pointer is `nil` or if some other condition is met, and then calls a `free_ressource` on the pointer. This is literally no different from what you would do in Rust with `Drop`.