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 8704381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:05:33+00:00 2026-06-13T03:05:33+00:00

I am working on a project where a certain class hierarchy implements IDisposable. Some

  • 0

I am working on a project where a certain class hierarchy implements IDisposable.

Some of the classes also implement a Finalize method ( ~MyClass() )

In general it looks something like this:

public class BaseClass : IDisposable
{
}

public class SomeClass : BaseClass
{
    ~SomeClass()
    {
        Dispose();
    }

    Dispose()
    {
        // Do some stuff.
        base.Dispose();
    }
}

public class AnoterClass : SomeClass
{
    ~AnoterClass()
    {
        Dispose();
    }

    Dispose()
    {
        // Do some stuff.
        base.Dispose();
    }
}

I’d like to know what is the proper way of handling calls to Dispose, as it seems that these objects are being disposed by calling Dispose(), and later on crash since the Finalize method is called.

Is it best to keep a flag at the lowest class in the hierarchy (protected bool disposed), and check that in every level of the class hierarchy?

I find that every possible solution requires some code duplication, which is not what i’m after.

  • 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. Editorial Team
    Editorial Team
    2026-06-13T03:05:34+00:00Added an answer on June 13, 2026 at 3:05 am

    You need to suppress finalization if you are manually disposing of your objects.

    The pattern to follow is here

    Edit:

    I think you only need to implement at a particular level of class hierarchy if you have something new to dispose at that level, otherwise I believe that the disposal in the base class will do everything that you need. If your implementation in any particular class just calls base.Dispose(disposing) then it is not needed, if it has to do some clean uop, then call base.Dispose() then you need it.

    Having a protected flag as you suggest should be fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a Openxml Excel Processing project. In a certain class I
I am working on a project where the button needs to have a certain
I am working on project where I have the checkInternet method in one of
I am working on a project where I have a class which has UIView
I'm working on a large-size dual AS3/Flex project (some parts are pure AS3, other
I have been working on a project where I have a Worker class that
Im working on a java project for a class which has a user enter
So basically I am working on a class project where we make our own
I'm working on a project where certain objects are referenced counted -- it's a
I'm working on a Qt/C++ open source project that uses MySQL databases. One class

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.