I have a tree data structure, that has functions to create different nodes. Those functions take an allocator and create a node pointer and do all the stuff internally. This works and using an arena allocator it’s easy to clear the whole tree.
But what if I don’t want to use an arena? I would have to recursively go through the tree and destroy every node, which makes sense, since it’s basically reversing the create calls. Is there an idiomatic way to make this easier/simpler? My guess would be to write a function inside the nodes .destory(self: *Node, alloc: Allocator) or something similar and then they do the destroy calls recursively themselves, hidden away. While would likely work, I was just wondering what the „zig-way“ would be