I think it is usefull to understand when SuppressFinalize() should be used.
If you look at code like this:

public class UseResource
{
  public void OpenResource()
  {
    // open a resource for use
  }

  public void UseResource()
  {
    // Do some stuff with the resource
  }

  public void CloseResource()
  {
    // close the resource
    SuppressFinalize();  // <== make sure Finalize is not called
  }

  ~UseResource()
  {
    // close the resource
  }


A good coder will open the resource, use it multiple times and call the
CloseResource() at the end (hopefully in a finally block). This will call
the SuppressFinalize() letting the GC know that cleanup has been done.

But if the user did not call the CloseResource explicitly, it will get
closed through the destructor and not left dangling.

As to the public constructor on the Singelton class, it does look strange.

Noam

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to