Say I have the following:
public abstract class ControlLimitBase : IDisposable
{
}
public abstract class UpperAlarmLimit : ControlLimitBase
{
}
public class CdsUpperAlarmLimit : UpperAlarmLimit
{
}
Two Questions:
1.
I’m a little confused on when my IDisposable members would actually get called. Would they get called when an instance of CdsUpperAlarmLimit goes out of scope?
2.
How would I handle disposing of objects created in the CdsUpperAlarmLimit class? Should this also derive from IDisposable?
Dispose()is never called automatically – it depends on how the code is actually used.1.)
Dispose()is called when you specifically callDispose():2.)
Dispose()is called at the end of ausingblock using an instance of your type.The
usingblock is syntactic sugar for atry/finallyblock with a call toDispose()on the object “being used” in the finally block.