I am making a large project: a mobile DAW with a few hundred classes and some of the most important classes need to have their pointers shared around the place. These important classes need to be able to hold pointers to each other, and even to hold pointers to themselves so that they can pass that pointer along to their client classes to have access to their functionality. It is a very complex web of classes.
So, I have mostly been using std::shared_ptr as a means of sharing these pointers around, but this can lead to problems as the app is shutting down: Class A cannot call its destructor because Class B is holding a shared_ptr of Class A. And Class B will not shut down and destroy its pointer to Class A because Class A is still holding a share_ptr of Class B.
My current solution is to create a shutdown() method on each class, where it will destroy all the pointers it owns. But this is an imperfect solution, especially as my company grows and the project expands rapidly. Anybody willing to share their methods of dealing with similar issues? I am considering using Juce::WeakReference instead of std::shared_ptr so that I can take control of when my pointers get deleted.