I have two classes ClassA and ClassB both having a reference to a singleton object ClassHelper. My question is how should i dispose the singleton object once im done using both the ClassA and ClassB
Edit:
public ClassA
{
CHelper obj;
public ClassA()
{
obj = obj.GetInstance("Initialise");
obj.CallFuncA();
}
}
On the same lines
public ClassB
{
CHelper obj;
public ClassB()
{
obj = obj.GetInstance("Initialise");
obj.CallFuncB();
}
}
where
CHelper
{
private static sm_CHelper;
public static GetInstance(string strInitialise)
{
if(sm_CHelper == null)
{
sm_CHelper = new CHelper(strInitialise);
}
}
private CHelper(string strInitialise)
{
//do something here
}
public CallFuncA()
{
// do something here
}
public CallFuncB()
{
// do something here
}
}
Regards Learner
if you are talking about the pattern singelton then you should not dispose it.... if your not referring to the singelton pattern then you could try to use the deconstructor to run your dispose logic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With