Tbh I would avoid the scenario of such fine-grained owning pointers in structs as much as possible in the first place, because once you have such a C++ style destructor function, the next thing you’d ineviatably want is a “copy” and “move” operation, and then you’ll need to start tracking ownership and lifetime manually and before you know it you’ll start thinking that maybe refcounting wasn’t such a bad idea, and at that point you can just switch back to C++ ![]()
IMHO in any language without RAII or garbage collection the best approach for simple structs is to not have any data ‘dangling off’ the struct, so that passing the struct around is always safe with a simple assignment, and a ‘destruction’ is a no-op. For complex objects, move ownership completely into a system, and use “generation-counted index handles” instead of pointers to identify an object (e.g. Handles are the better pointers).
Another approach somewhere in the middle is to let arenas completely own their items. IMHO the fine-grained deallocation in deinit functions are at odds with this idea. Once you manage memory with arenas, also let the arena manage ownership and lifetime (e.g. the arena owns its allocations, not some object which allocated from the arena, and all allocations in an arena share the same lifetime).
Just my 2ct ![]()