title: Garbage collection on a closed-over object
body: <p><strong>NOTE</strong> The code below is from asp.net.</p>
  
  <hr>
  
  <p>If I have the (poorly written) code below</p>
  
  <pre><code>AmazonS3 s3Client = Amazon.AWSClientFactory.CreateAmazonS3Client();
  
  // ...
  // details elided
  // ...
  
  BackgroundWorker worker = new BackgroundWorker();
  
  worker.DoWork += new DoWorkEventHandler((s, args) =&gt;
  {
      s3Client.PutObject(titledRequest);
  });
  
  new Thread(() =&gt; worker.RunWorkerAsync()).Start();
  </code></pre>
  
  <p>Will the garbage collector be smart enough to never, ever collect the <code>s3Client</code> object until the background worker is done with it?</p>
  
  <hr>
  
  <p>Note, I'm kicking off the background worker inside of a thread only in order to fix an annoying error that gets raised within asp.net that happens when I fire off the background worker directly.</p>