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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:07:39+00:00 2026-05-26T04:07:39+00:00

Do I have to use a using statement to dispose immediately even in a

  • 0

Do I have to use a using statement to dispose immediately even in a method? Or will the ending of the method cause an automatic Dispose of all local variables including graphics?
(I’m asking this because I’ve seen examples that have Dispose calls at the end of methods, and wanted to know if that’s really necessary.)

Thanks.

  • 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-26T04:07:40+00:00Added an answer on May 26, 2026 at 4:07 am

    Yes, you do. Going out of scope does not do anything; it does not call Dispose(), it does not garbage-collect, it does not call a finalizer.

    If the type is IDisposable, then yes. It is your job to tidy up after yourself (assuming that the object is actually “done with” at this point).

    Possible side-effects of not doing this:

    • files get left open and cause access-exceptions (FileStream)
    • connections get left open and cause pool saturation (DbConnection)
    • unmanaged handles get saturated and cause resource starvation (any winforms/etc)
    • transactions get left open and cause blocking (TransactionScope / DbTransaction)
    • etc

    basically, bad things.

    Furthermore, in most cases where you see Dispose() at the bottom of the method, a using would be preferable. There are some cases where that isn’t possible (fields on an object, for example), but the point remains: it sounds like those are bad examples.

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

Sidebar

Related Questions

I have two questions. 1) Should you always use a using statement on a
Is it possible to use the using declaration with template base classes? I have
I've just started using Java's enums in my own projects (I have to use
I am interested in using/learning RoR in a project where I have to use
I am trying to use PHP session without using cookies. I have enabled session.use_trans_sid
I've been developing a site using ASP.NET MVC, and have decided to use the
I have been using Jquery alot lately an was wondering if I should use
I recently began using BIRT and have developed a report to use with my
I have been using Visual Studio Express versions. I used to use the full
I have been using mootools for a year now. I need to use jquery

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.