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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:09:24+00:00 2026-06-03T06:09:24+00:00

I have two classes, say class MyFirstClass and MyAnotherClass , MyAnotherClass is implementing IDiposable

  • 0

I have two classes, say class MyFirstClass and MyAnotherClass , MyAnotherClass is implementing IDiposable interface.

public class MyFirstClass
{
   public string xyz{get;set;} ..... and so on
}


public class MyAnotherClass : IDisposable
{
   private readonly MyFirstClass objFc = new MyFirstClass();
   public static  void MyStaticMethod()
   {
        var objOfFirstClass = new MyFirstClass();
        // something with above object
   }

   public void MyNonStaticMethod()
   {
      // do something with objFc
   }

   #region Implementation of IDisposable
    .... my implementations
   #endregion
}

Now I have one more class where I am calling MyAnotherClass , something like this

using(var anotherObj = new MyAnotherClass())
{
   // call both static and non static methods here, just for sake of example.
   // some pretty cool stuffs goes here... :)
}

So I would like to know, should I worry about the cleanup scenario of my objects? Also, what will happen to my ObjFC (inside non static) and the objOfFirstClass (inside static).

AFAIK, using will take care of everything…but i need to know more…

  • 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-03T06:09:25+00:00Added an answer on June 3, 2026 at 6:09 am

    objOfFirstClass is a local variable in a method. It will be eligible for garbage collection once the method is exited. It won’t be disposed as such because it doesn’t implement IDisposable.

    objFc will be eligible for garbage collection when its parent object goes out of scope. Again, this is nothing to do with disposing it.

    Dispose/IDisposable is used when there is clean up other than simple memory management to be done. The CLR handles cleaning up the memory for you using garbage collection. using is a nice way of ensuring that an object implementing IDisposable has its Dispose method called when you have finished with it – but if all you are after is memory management, you don’t need to use it.

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

Sidebar

Related Questions

Lets say I have two classes: class A { [SortOrder(3)] public string Name {
Say you have these two classes. public class Author { public int ID {get;
Say you have two classes, order and customer: public class Customer{ public int CustomerId
Let's say we have these two classes: public class Base { public static int
Let's say I have two classes like the following: Class A { public: ..
Let's say I have two classes that look like this: public class ByteFilter {
Say I have two classes which extend Event : public class CustomEventOne extends Event
Say, I have two classes: @XmlRootElement class A { @XmlElement String propertyOfA; @XmlElement B
Lets say I have two classes: public class A { public virtual int Id
Say I have two classes, in two different headers, called: class TestA { public:

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.