disposing a singleton

G

Guy

Hi all,



I'm using the following architecture:

I have a singleton class (lets call it Manager class) that creates and holds
a reference to a BlockingQueue and a listener to that queue.

The class sends the listener to listen to the queue in another thread to
prevent the processing of the queue data to affect the main Thread
execution.



All the methods of the Manager class are static.



The Manager class implements the IDisposable interface.



The problem is that once the process is going down the Manager is not
disposed so the queue the listener and the Manager stay stuck in the
memory.



The only solution I could find is to call the Manager Dispose method from
another class's Dispose().



Does anyone know how can I avoid this 'Spaghetti' coding and make the
Manager class manage its own disposing?
 
D

Daniel Moth

Looking at your title, you should try to design your singletons to be free
from disposing requirements (they should live through the lifetime of an
application).

Looking at the content of your post, look into finalisers (Finalize method
in VB, destructor in C#).

Cheers
Daniel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top