Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 176421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:52:26+00:00 2026-05-11T13:52:26+00:00

What follows is a typical dispose pattern example: public bool IsDisposed { get; private

  • 0

What follows is a typical dispose pattern example:

 public bool IsDisposed { get; private set; }    #region IDisposable Members    public void Dispose()   {     Dispose(true);     GC.SuppressFinalize(this);   }    protected virtual void Dispose(bool disposing)   {     if (!IsDisposed)     {       if (disposing)       {         //perform cleanup here       }        IsDisposed = true;     }   }    ~MyObject()   {     Dispose(false);   } 

I understand what dispose does, but what I don’t understand is why you would want to call dispose(false) in the destructor? If you look at the definition it would do absolutely nothing, so why would anyone write code like this? Wouldn’t it make sense to just not call dispose from the destructor at all?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T13:52:27+00:00Added an answer on May 11, 2026 at 1:52 pm

    The finalizer is used as a fall-back if the object is not disposed properly for some reason. Normally the Dispose() method would be called which removes the finalizer hookup and turns the object into a regular managed object that the garbage collector easily can remove.

    Here is an example from MSDN of a class that has managed and unmanaged resources to clean up.

    Notice that the managed resources are only cleaned up if disposing is true, but unmanaged resources is always cleaned up.

    public class MyResource: IDisposable {     // Pointer to an external unmanaged resource.     private IntPtr handle;     // Other managed resource this class uses.     private Component component = new Component();     // Track whether Dispose has been called.     private bool disposed = false;      // The class constructor.     public MyResource(IntPtr handle)     {         this.handle = handle;     }      // Implement IDisposable.     // Do not make this method virtual.     // A derived class should not be able to override this method.     public void Dispose()     {         Dispose(true);         // This object will be cleaned up by the Dispose method.         // Therefore, you should call GC.SupressFinalize to         // take this object off the finalization queue         // and prevent finalization code for this object         // from executing a second time.         GC.SuppressFinalize(this);     }      // Dispose(bool disposing) executes in two distinct scenarios.     // If disposing equals true, the method has been called directly     // or indirectly by a user's code. Managed and unmanaged resources     // can be disposed.     // If disposing equals false, the method has been called by the     // runtime from inside the finalizer and you should not reference     // other objects. Only unmanaged resources can be disposed.     private void Dispose(bool disposing)     {         // Check to see if Dispose has already been called.         if(!this.disposed)         {             // If disposing equals true, dispose all managed             // and unmanaged resources.             if(disposing)             {                 // Dispose managed resources.                 component.Dispose();             }              // Call the appropriate methods to clean up             // unmanaged resources here.             // If disposing is false,             // only the following code is executed.             CloseHandle(handle);             handle = IntPtr.Zero;              // Note disposing has been done.             disposed = true;          }     }      // Use interop to call the method necessary     // to clean up the unmanaged resource.     [System.Runtime.InteropServices.DllImport('Kernel32')]     private extern static Boolean CloseHandle(IntPtr handle);      // Use C# destructor syntax for finalization code.     // This destructor will run only if the Dispose method     // does not get called.     // It gives your base class the opportunity to finalize.     // Do not provide destructors in types derived from this class.     ~MyResource()     {         // Do not re-create Dispose clean-up code here.         // Calling Dispose(false) is optimal in terms of         // readability and maintainability.         Dispose(false);     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 117k
  • Answers 117k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer AFAICR, Oracle always stores VARRAY's out of row in the… May 11, 2026 at 10:41 pm
  • Editorial Team
    Editorial Team added an answer You can try devenv.exe /setup on a (elevated) command prompt.… May 11, 2026 at 10:41 pm
  • Editorial Team
    Editorial Team added an answer You sure you load the SQL Native Driver for 2005,… May 11, 2026 at 10:41 pm

Related Questions

I have a form that sits behind ASP.NET forms authentication. So far, the implementation
I have a sea of weighted nodes with edges linking clusters of nodes together.
What advantage, if any, is provided by formatting C code as follows: while(lock_file(lockdir)==0) {
I'm using the Zend framework and the openid selector from http://code.google.com/p/openid-selector/ - however I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.