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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:15:43+00:00 2026-05-24T12:15:43+00:00

Possible Duplicate: Any sense to set obj = null(Nothing) in Dispose()? I understand if

  • 0

Possible Duplicate:
Any sense to set obj = null(Nothing) in Dispose()?

I understand if this question is closed as a duplicate, but I’m having some trouble reconciling some posts on this topic.

First a little background. I have a class Foo as follows

public class Foo : IDisposable
{
    private Dictionary<int, string> _reallyBigDictionary = 
            new Dictionary<int, string>();

    public void Dispose()
    {
        _reallyBigDictionary = null;
    }
}

Instances of Foo are known to have a limited scope (i.e. I know we’re not keeping it around forever). Given it’s instance’s limited scope, I don’t see how nulling out _reallyBigDictionary actually frees up memory sooner than the dispose. The way I understand it, these objects won’t ever get cleaned up until garbage collection is run. At that time, references to the given instance of Foo will be null regardless, so I expect GC to reclaim that memory regardless.

These posts lead me to believe that there is no point in setting member variables to null:

Memory leak problems: dispose or not to dispose managed resources?

Is it better to destroy all objects or just let the garbage collector do the job?

This post makes me question otherwise:
Proper use of the IDisposable interface

Can anyone clarify this point for me? Is the IDisposable implementation really necessary here? Because I just can’t convince myself it is.

  • 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-24T12:15:44+00:00Added an answer on May 24, 2026 at 12:15 pm

    You don’t need IDisposable; here’s why. In summary, you need to follow Rule 1: Don’t implement IDisposable unless you need to.

    There are only two situations when IDisposable does need to be implemented:

    • The class owns unmanaged resources.
    • The class owns managed (IDisposable) resources.

    Since Dictionary<int, string> is not IDisposable, your class shouldn’t be either.

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

Sidebar

Related Questions

Possible Duplicate: Reference: Comparing PHP's print and echo Is there any major and fundamental
Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be
Possible Duplicate: Does it make sense to use the <table> tag on a “modern”
Possible Duplicate: Is there any danger in calling free() or delete instead of delete[]?
Possible Duplicate: C/C++ - Any good web server library? What well known C/C++ libraries
Possible Duplicate: Generate line graph for any benchmark? What services do you recommend to
Possible Duplicate: Are there are any platforms where pointers to different types have different
Possible Duplicate: How to find whether a string contains any of the special characters?
Possible Duplicate: Does adding [Serializable] to the class have any performance implications? What is
Possible Duplicate: iPhone CATransition adds a fade to the start and end of any

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.