title: Does the Garbage Collector destroy temporarily unreferenced objects during async calls in .NET?
body: <p>Imagine that I will make an async call in .NET, i.e. HttpWebRequest.BeginGetResponse, and the HttpWebRequest object isn't referenced at a broader scope. Will the Garbage Collector destroy it and cause problems?</p>
  
  <p>Example code:</p>
  
  <pre><code>using System;
  using System.Net;
  
  public class AsyncHttpWebRequest
  {
      void Main()
      {
          var Request = HttpWebRequest.Create("http://www.contoso.com");
          var result = Request.BeginGetResponse(GetResponseCallback, null);
      }
  
      private void GetResponseCallback(IAsyncResult AsyncResult)
      {
          // Do Something..
      }
  }
  </code></pre>
  
  <p>Alternate version (with the request being passed as an AsyncState):</p>
  
  <pre><code>using System;
  using System.Net;
  
  public class AsyncHttpWebRequest
  {
      void Main()
      {
          var Request = HttpWebRequest.Create("http://www.contoso.com");
          var result = Request.BeginGetResponse(GetResponseCallback, Request);
      }
  
      private void GetResponseCallback(IAsyncResult AsyncResult)
      {
          // Do Something..
      }
  }
  </code></pre>