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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:13:46+00:00 2026-05-30T15:13:46+00:00

In C#, if a class, such as a manager class, does not have resources,

  • 0

In C#, if a class, such as a manager class, does not have resources, is there any benefit to having it : IDisposable?

Simple example:

public interface IBoxManager
{
 int addBox(Box b);
}

public class BoxManager : IBoxManager
{
 public int addBox(Box b)
 {
  using(dataContext db = new dataContext()){
   db.Boxes.add(b);
   db.SaveChanges();
  }
  return b.id;
 }
}

Will there be any benefit in memory use when using BoxManager if it also implements IDisposable? public class BoxManager : IBoxManager , IDisposable

For example:

BoxManager bm = new BoxManager();
bm.add(myBox);
bm.dispose();//is there benefit to doing this?
  • 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-30T15:13:48+00:00Added an answer on May 30, 2026 at 3:13 pm

    There are only 2 reasons for implementing IDisposable on a type

    • The type contains native resources which must be freed when the type is no longer used
    • The type contains fields of type IDisposable

    If neither of these are true then don’t implement IDisposable

    EDIT

    Several people have mentioned that IDisposable is a nice way to implement begin / end or bookended operations. While that’s not the original intent of IDisposable it does provide for a very nice pattern.

    class Operation {
      class Helper : IDisposable {
        internal Operation Operation;
        public void Dispose() {
          Operation.EndOperation();
        }
      }
      public IDisposable BeginOperation() {
        ...
        return new Helper() { Operation = this };
      }
      private void EndOperation() {
        ...
      }
    }
    

    Note: Another interesting way to implement this pattern is with lambdas. Instead of giving an IDisposable back to the user and hoping they don’t forget to call Dispose have them give you a lambda in which they can execute the operation and you close out the operation

    public void BeginOperation(Action action) {
      BeginOperationCore();
      try {
        action();
      } finally {
        EndOperation();
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a simple class such as:- @XmlRootElement public class MyClass { @XmlAttribute(required=true)
If I have a base class such that public abstract class XMLSubscription <T extends
In AS3, if I have a class such: public class dude { //default value
I have such class public unsafe class EigenSolver { public double* aPtr {get; private
I often have this kind of situation - there's a simple plain class, say,
Given a class such as: class Person { private: char *name; public: Person() {
I have 3 abstract classes (Customer, Tender, Site). For Customer has inherited class such
If I have class names such as left, right, clear and xhtml like <a
There's a resource manager class. It helps us to access devices. But, of course,
We have the following shared component: public class OurServiceBase : System.ServiceProcess.ServiceBase This class has

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.