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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:19:00+00:00 2026-06-01T17:19:00+00:00

I know C# can manage resource pretty well with its garbage collector. But since

  • 0

I know C# can manage resource pretty well with its garbage collector. But since it has that, what exactly is this for and why is it needed?

Can anyone explain why .Dispose() is needed in asp.net mvc?

Also, what does it mean to Dispose a connection? Why is it needed? Anyone know the intricacies of why it’s important to dispose a database connection like in db.Dispose()? Is this EF-related, or SQL Server-related? I’m trying to understand exactly why.

protected override void Dispose(bool disposing)
{
   db.Dispose();
   base.Dispose(disposing);
}
  • 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-01T17:19:01+00:00Added an answer on June 1, 2026 at 5:19 pm

    Dispose is for releasing “unmanaged” resources (for example, sockets, file handles, Bitmap handles, etc), and if it’s being called outside a finalizer (that’s what the disposing flag signifies, BTW), for disposing other IDisposable objects it holds that are no longer useful.

    “Unmanaged” resources aren’t managed by the CLR (hence the name), and GC doesn’t mess with them or free them all by itself; absent a Dispose method (and code actually using it!), it’ll rely on the object’s finalizer to clean up. Eventually the finalizer will run (if the app’s healthy, and the object has a finalizer), and if the finalizer does its job then all’s semi OK….but it’ll take its sweet time in doing so — and if you run out of handles in the meantime, oh well. Too bad for that other thread/process/whatever that needed them.

    If you Dispose, though, the resources are released immediately, and things run better all around.

    (By the way, this is not restricted to EF, SQL Server, or any other technology. The Disposable pattern is found throughout the .net framework, and it’s considered good practice to take advantage of it whenever you have an IDisposable that’s no longer being used.)

    As for why IDisposable is implemented so far up the tree, rather than you just implementing it on a case by case basis…i’m not 100% sure. But imagine you were writing a framework. Consider that if everything weren’t an IDisposable, you’d have to check — every time you wanted to get rid of something! — whether the object is disposable, and Dispose it if so. If you instead implement IDisposable “just in case”, though, things are simplified — you just always dispose. (If an object doesn’t have anything to clean up, it just doesn’t override Dispose — in which case its parent’s Dispose gets called and does whatever cleanup it has to, which may be nothing as well…) And it’s a common enough case for controllers to have stuff to clean up, that even if that’s not the real reason, it makes a lot of sense to do anyway.

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

Sidebar

Related Questions

I know that you can use static libraries to manage dependencies for iOS apps.
I have a query that I know can be done using a subselect, but
I know this has been discussed ad nauseum...but I have an issue with the
i want know how i can manage multiple twitter account on iOS in my
I would like to know if there is an existent framework which can manage
Does someone know of a Sqlite manager that I can put on my site,
This is something I know can be done somehow , because I've done it
Sometimes, I'll end up having to catch an exception that I know can never
You can know if the event stack is empty calling the gtk.events_pending() method, but
I just can't seem to figure this one out... As far as I know,

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.