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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:33:58+00:00 2026-06-09T19:33:58+00:00

Does the end of the using block get hit if a return is called

  • 0

Does the end of the using block get hit if a return is called inside of it? For example,

using( var ur = new UnmanagedResource() )
{
  if( SomeCondition == true ){
   return SomeReturnValue;
  }
}

When SomeCondition is true, will the UnmanagedResource be disposed from the end of the using block before the return is called? What is the order of operations behind the scenes that would take place in this scenario?

  • 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-09T19:34:00+00:00Added an answer on June 9, 2026 at 7:34 pm

    The object is disposed prior to the control flow returning to the caller of the method.

    This is detailed in the C# language specification, section 8.9:

    Execution of jump statements is complicated by the presence of intervening try statements. In the absence of such try statements, a jump statement unconditionally transfers control from the jump statement to its target. In the presence of such intervening try statements, execution is more complex. If the jump statement exits one or more try blocks with associated finally blocks, control is initially transferred to the finally block of the innermost try statement. When and if control reaches the end point of a finally block, control is transferred to the finally block of the next enclosing try statement. This process is repeated until the finally blocks of all intervening try statements have been executed.

    …

    finally blocks associated with two try statements are executed before control is transferred to the target of the jump statement.

    Since a using statement is turned into a try/finally (detailed in 8.13), this means the Dispose call is guaranteed to occur “prior to the return” (rather, prior to control flow jumping to the caller of this method), as return is a “jump statement”.

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

Sidebar

Related Questions

Possible Duplicate: Does Dispose method still get called when Exception is thrown inside of
What does the keyup() at the end of it mean? $(input).keyup(function () { var
My end goal is to get Erlang syntax highlighting in QsciScintilla using PyQt4 and
So I understand that at the end of a using block statement, the dispose
My compiled Go code does not end with an extension on Linux. Any tips
when including libraries c, the line does not end with a semicolon, while other
Why does the Standard define end() as one past the end, instead of at
How exactly does adding a random number to the end of an AJAX server
Winforms - why does a Show() after a system tray double click end up
Why does this fail, it's supposed to be simple and work ? fisier.seekg(0, ios::end);

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.