One area I have been focusing on in my game engine recently is memory management. Up until now, I have pretty much just been using raw pointers, and simply keeping in mind what is supposed to clean up what. It's worked great so far, but it just isn't very scalable, and I'm now looking for alternatives.
I have been thinking about how a garbage collector could be implemented in C++, and I I've come up with a few ways. One thing I've always disliked about garbage collectors however is that they just don't tell you anything about the relationship between objects (you lose any sense of ownership with a garbage collector, which is one thing I really dislike when working with managed languages. Even when knowing what owns what is irreverent for memory management purposes, it just tells you so much more about how the application works at a glance). With that in mind, I've been thinking of developing a memory model similar to std::unique_ptr and std::weak_ptr.
In such a system, for every dynamically allocated block there would be one unique_ptr, and an unlimited number of weak_ptrs (obviously this doesn't work with the the standard library versions because you can't assign a weak_ptr to a unique_ptr, but that is one thing I plan on changing). Ownership cycles would have to be detected (make sure an object doesn't hold a unique_ptr to itself), but other than that everything could be tracked using normal c++ constructors and destructors. This system is appealing to me, because it would be much simpler to implement than a garbage collector, and possibly be more efficient. However, making such a system thread-safe may be more difficult, and may end up being just much more restricting and difficult to use than a garbage collector.
I've been trying to read about this online, but the vast majority of results for "Memory management in C++" lead to articles on the very basics of using new/delete, which I already understand.
How have you solved this problem in your projects?
Thanks