I have a compiled external library that I’m using in my (Objective-C++) code. This library has a singleton class to store some information throughout the duration of the application being used. I really need a way to be able to remove the loaded information and reload it in the middle of the application. Or to reload the application so that this singleton is reinitialised.
In the header files there is no way to reset the class information.
The way I get an instance of it is:
Singleton::getInstance();
In the header file this is shown as:
static Singleton& getInstance();
I would like a way to be able to delete this instance and reinitialise another instance.
Is there any way to do this? This singleton is only being used on one (the main) thread.
Extra information
When the application first loads I have to call:
Singleton::getInstance().load();
so that it loads information from the Documents directory of the app and create an internal structure. I replace those files in the Documents directory in the middle of the application running and I want it to reinitialise. If I call the above function again I get an error because the person who wrote this library doesn’t allow the load function to be called twice.
I tried some stuff like:
delete &Singleton::getInstance();
but I don’t know how I should reinitialise it afterwards. As calling
Singleton::getInstance();
crashes the app.
Unless the API is providing you a way to do it, it’s probably impossible.
But I would have try to rerun the “load” function after I call the delete…