If I create a singleton class in the context of a dll or bundle on mac, the singleton class is instantiated once and used by all instances of the dll. I am using a dll as a plug-in for an application. Now the following thing came to my mind: If I use a singleton Class, it will be shared across multiple instances of the plug-in. However, this makes it difficult to manage the lifetime of the singleton class efficiently. The only way I could think of would be to use a reference count and to make the singleton delete its self when the reference count is 0. 

Does anyone have any better ideas on that? Is there any good way to restrict the singleton object to one instance of the dll?

Language is c++, but the solution has to work under windows and mac (being a bundle here). The specification for the dll or bundle are given by the application, so there is nothing to change here.