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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:09:57+00:00 2026-05-16T18:09:57+00:00

I have a class which implements IDisposable interface. using System; class A : IDisposable

  • 0

I have a class which implements IDisposable interface.

using System;

class A : IDisposable
{
        public void Dispose()
        {
            Stop(); // some actions to stop internal threads

            this = null;
        }
}

Why can’t I assign this = null in Dispose method ? I know ‘this’ is read-only.

For example:

A a = new A();
a.Run();
// ...
a.Dispose();
// i want in this line a = null

I thought IDisposable and Dispose method guarantee that instance of class A will be equals to null after calling Dispose(). But it’s not true.

  • 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-16T18:09:57+00:00Added an answer on May 16, 2026 at 6:09 pm

    Just to add to what’s already been said:

    It’s important to realize that there are objects, and there are references (variables), and these are not the same thing.

    When you write var a = new object(); you’re doing two things:

    1. Creating a new object instance. This instance has no “name” — just a location in memory. It is what it is. But, just so we have something to call it, let’s call it “Bob.”
    2. Declaring a variable a, which references the object just created.

    Now, when you write a = null;, you’re doing nothing to Bob. You’re changing a to reference, instead of Bob, null, or in other words, “no object.” So you can no longer access “Bob” using a.

    Does this mean now Bob doesn’t exist? No. Bob’s still right where he was.

    Consider this (which is basically the scenario Henk mentioned):

    var a = new object(); // Again, we're calling this object Bob.
    object b = a;
    

    Now, b is another variable, just like a. And just like a, b references Bob. But again, just as with a, writing b = null; does nothing to Bob. It just changes b so that it no longer points to an object.

    Here’s where I’m going with this. You seem to have been under the impression that doing this:

    a.Dispose();
    

    …somehow also did this:

    a = null;
    

    …which was somehow equivalent to doing this:

    Bob= null; // nowBobis no object?

    But if that were the case, then b (above) would now point to no object, even though it was never set to null!

    Anyway, from my explanation above, hopefully it is clear that this is simply not how the CLR works. As Jon has pointed out, the IDisposable interface is actually not related to memory being freed. It is about releasing shared resources. It does not — cannot — delete objects from memory, as if it did then we would have the behavior I’ve described above (references suddenly becoming invalid out of nowhere).

    I know this was only loosely related to your specific question about IDisposable, but I sensed that this question was coming from a misconception about the relationship between variables and objects; and so I wanted to make that relationship clearer.

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

Sidebar

Related Questions

I am using some threads in java android, I have a class which implements
I have class Money which is an @Embeddable @Embeddable public class Money implements Serializable,
Suppose I have a class DisposableObject which implements IDisposable. There is a risk it
I have a simple class MyDataClass with a member (obj) that implements IDisposable: public
I have a class which implements the RememberMeServices and LogoutHandler interface. I have turned
I have a class A which implements the interface serializible. There are two sub
Let's say I have a class that implements the IDisposable interface. Something like this:
If I have a SomeDisposableObject class which implements IDisposable : class SomeDisposableObject : IDisposable
I have the following class which uses BinaryReader internally and implements IDisposable. class DisposableClass
For example I have SomeClass class which implements ISomeInterface interface with two properties Prop1

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.