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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:19:59+00:00 2026-05-12T13:19:59+00:00

I have been looking at the standard Dispose pattern and I’m just wondering what

  • 0

I have been looking at the standard Dispose pattern and I’m just wondering what I need to write to free managed resources? If these resources are ‘managed’ already then surely I shouldn’t need to do anything.

If that’s the case, and my class doesn’t hold any unmanaged resources (hence no need for it to be finalized by GC) then do I only need to suppress finalization in my Dispose method? :-

public void Dispose()
{
   GC.SuppressFinalize(this);
}

so suppose this is my class:

public sealed class MyClass : IDisposable
{
    IList<MyObject> objects; // MyObject doesn't hold any unmanaged resource
    private bool _disposed;

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    private void Dispose(bool disposing)
    {
        if (!_disposed)
        {  
            // do I need to set the list to null and 
            // call Dispose on each item in the list?
            if (disposing)
            {
                foreach (var o in objects)
                    o.Dispose();

                objects = null;
            }
        }

        _disposed = true;
    }

    ~MyClass()
    {
        Dispose(false);
    }
}

Do I actually need to free the managed resources here?

Thanks,

  • 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-12T13:19:59+00:00Added an answer on May 12, 2026 at 1:19 pm

    If your class holds any IDisposable instances, you’re using managed resources and thus you should implement IDisposable to allow users to dispose of the resources. Your Dispose method should call Dispose on the managed resources.

    As for freeing managed memory, you don’t need to do anything. That is handled by GC, but that is the only part of the cleanup that is handled by GC. Managed and unmanaged resources must be cleaned up by Dispose and/or finalizers.

    If you don’t use any managed or unmanaged resources, there is no need to implement neither IDisposable nor a finalizer. Implementing a finalizer will actually impact the performance of your type, so don’t implement it unless you need it.

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

Sidebar

Related Questions

I have been looking for an elegant way to write a function that takes
Have been looking on some tutorials for drawing canvas using SurfaceView, but the only
I have been looking around for a visualization framework that would aid graph visualization
I have been looking online to find documentation for the function in QTP and
I have been looking into AWS spot instances for some jobs however instead of
I have been looking into backbone.js and I can't seem to figure out how
I have been looking at the Thinktecture.IdentityModel.40 library as a way of handling the
I have been looking for an answer to this on Stack Overflow, but I
I have been looking through the source code for the Flash-based Google TV example
I have been looking at this for to long so I am tossing it

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.