PC Review


Reply
Thread Tools Rate Thread

disposing a singleton

 
 
Guy
Guest
Posts: n/a
 
      21st Apr 2005
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?



Guy




 
Reply With Quote
 
 
 
 
Chris Mayers
Guest
Posts: n/a
 
      21st Apr 2005
I'm no expert in this, but surely if you are using a static class then there
is not an instance of the class to dispose of, especially if the queue and
listener are also static, hence anything created in these static methods
will hang arround until it is explicitly disposed of, or the system is
closed down...

The only thing I can think of is to declare a static method in the Manager
class call somthing like TidyUp which closes everything down and tidies
up...

Alternativley, if it is practical, remove the static modifier on all items
of the class, create an instance of the Manager class and call your methods
on that, then when you close down things should tidy themselves...

"Guy" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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?
>
>
>
> Guy
>
>
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disposing Rob Microsoft ASP .NET 4 11th Jan 2007 01:47 PM
Disposing - when? TyBreaker Microsoft VB .NET 1 22nd Aug 2006 12:01 PM
Disposing Com+ Object sternr Microsoft C# .NET 3 10th Jan 2006 08:14 AM
disposing a singleton Guy Microsoft Dot NET Compact Framework 1 21st Apr 2005 11:07 PM
disposing of oe santy Windows XP Internet Explorer 4 3rd Jan 2004 01:25 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:57 PM.