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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:40:06+00:00 2026-05-10T16:40:06+00:00

I have a class that creates several IDisposable objects, all of these objects are

  • 0

I have a class that creates several IDisposable objects, all of these objects are then passed to another ‘manager’ class in a 3rd party library. As I need some of the objects in later calls I kept a local field reference to the created objects so that I could access them at a later time. When I ran FxCop on the class it said that I should implement IDisposable, due to the disposable objects that I kept a reference to. My questions are:

  1. Should I implement IDisposable for my class? (or is it the manager’s responsibility?)
  2. If so, should I only dispose the objects I kept a reference to? or should I find a way to dispose all objects I created.

My code:

public class MyClass   {       ClassThatIsDisposable aReference;   }  public MyClass(ManagerClass manager)   {       ClassThatIsDisposable transient=new ClassThatIsDisposable();       manager.Add(transient);       aReference=new ClassThatIsDisposable();       manager.Add(aReference);   }  public void LaterCall()   {       areference.Method();   }      
  • 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. 2026-05-10T16:40:07+00:00Added an answer on May 10, 2026 at 4:40 pm

    The class that owns the object is the one that should dispose of them… It sounds like your manager is the owner, so he should dispose of the object.

    If you’re trying to avoid the FXCop warning then one option is to have MyClass request the disposable object from the manager each time is needs to use it. This way you won’t have a member variable holding a reference to it. You could do this my having the Add() method return akey for the object that has been added and then use this key to retrieve the object from the manager when you need to use it.

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

Sidebar

Related Questions

I have a PHP class that creates a PNG image on the fly and
I have a class Page that creates an instance of DB , which is
I have a class that I want to use to store properties for another
I have a class that map objects to objects, but unlike dictionary it maps
I have a control that is created like so: public partial class MYControl :
I have a collection of classes that inherit from an abstract class I created.
I have class method that returns a list of employees that I can iterate
I have a class that I wish to expose as a remote service using
I have a class that looks like this public class SomeClass { public SomeChildClass[]

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.