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

  • SEARCH
  • Home
  • 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 434101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:14:24+00:00 2026-05-12T20:14:24+00:00

I have an abstract class that implements IDisposable, like so: public abstract class ConnectionAccessor

  • 0

I have an abstract class that implements IDisposable, like so:

public abstract class ConnectionAccessor : IDisposable
{
    public abstract void Dispose();
}

In Visual Studio 2008 Team System, I ran Code Analysis on my project and one of the warnings that came up was the following:

Microsoft.Design : Modify ‘ConnectionAccessor.Dispose()’ so that it calls Dispose(true), then calls GC.SuppressFinalize on the current object instance (‘this’ or ‘Me’ in Visual Basic), and then returns.

Is it just being silly, telling me to modify the body of an abstract method, or should I do something further in any derived instance of Dispose?

  • 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-05-12T20:14:25+00:00Added an answer on May 12, 2026 at 8:14 pm

    You should follow the conventional pattern for implementing Dispose. Making Dispose() virtual is considered bad practice, because the conventional pattern emphasizes reuse of code in “managed cleanup” (API client calling Dispose() directly or via using) and “unmanaged cleanup” (GC calling finalizer). To remind, the pattern is this:

    public class Base
    {
        ~Base()
        {
            Dispose(false);
        }
    
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this); // so that Dispose(false) isn't called later
        }
    
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                 // Dispose all owned managed objects
            }
    
            // Release unmanaged resources
        }
    }
    

    Key here is that there’s no duplication between finalizer and Dispose for unmanaged cleanup, and yet any derived class can extend both managed and unmanaged cleanup.

    For your case, what you should do is this:

    protected abstract void Dispose(bool disposing)
    

    and leave everything else as is. Even that is of dubious value, since you’re enforcing your derived classes to implement Dispose now – and how do you know that all of them need it? If your base class has nothing to dispose, but most derived classes likely do (with a few exceptions, perhaps), then just provide an empty implementation. It is what System.IO.Stream (itself abstract) does, so there is precedent.

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

Sidebar

Related Questions

If I have a base class such that public abstract class XMLSubscription <T extends
I have an abstract class, AbsClass that implements an interface, IClass . IClass has
I have an abstract java class that implements a couple of its methods, but
Ok so I have an abstract base class called Product, a KitItem class that
I have a collection of classes that inherit from an abstract class I created.
I have an abstract class and I would like to use it quickly by
I have an abstract base class with a TcpClient field: public abstract class ControllerBase
I have an abstract class: type TInterfaceMethod = class abstract public destructor Destroy; virtual;
here's the code (simplified): public abstract class PageBase implements Serializable { private static final
I've written a class that implements IEnumerable<T> . I have a method that returns

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.