Using Interface to dispose and null and object



I may be on the wrong track here but I thought I could do this, but it isn't working.

I have a class which I have used a interface to define.

This class is then inherited from, and many of them are used (conditionally) on a form.

In order to simplify my dispose area, I thought I could use the interface to dispose and null the items, but it doesn't seem to work.

Eg.

public interface IDataModule : IDisposable
{ ... }

class ProductsDM : Candle.DataModule, IDataModule
{ ... }

class StatusDM : Candle.DataModule, IDataModule
{ ... }


Form Code
_____________

IDataModule CurrentModule;


Load method...

switch (SetupMode)
{
case SetupFormMode.SETUP_PRODUCTS:
{
ProductsModule = new DataModules.ProductsDM(....);
CurrentModule = ProductsModule;
}
break;
case SetupFormMode.SETUP_STATUSES:
{
StatusModule = new DataModules.StatusDM(....);
CurrentModule = StatusModule;
}
break;

}


Unload Method
if (CurrentModule != null)
CurrentModule.Dispose();
CurrentModule = null;


Now if I put a watch on CurrentModule and the Actually objects, the CurrentModule is null, but the others are fine.

Any help would be great.

Daniel


.



Relevant Pages

  • Re: Using Interface to dispose and null and object
    ... after I make the calls to dispose the CurrentModule and set to null the ... ProductsModule is still not null and I can browse its properties etc. ... World class .NET training in the UK: http://iterativetraining.co.uk ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Using Interface to dispose and null and object
    ... As you will see when you click the buttons on the form, it should clear the previous reference from CurrentModule and create the new one. ... ProductsModule is still not null and I can browse its properties etc. ... Jon Skeet - ... World class .NET training in the UK: http://iterativetraining.co.uk ...
    (microsoft.public.dotnet.languages.csharp)

Loading