title: Unity3D Coroutines and lambda callbacks, safety
body: <p>Is it safe to invoke System.Action that was declared in a coroutine?</p>
  
  <pre><code>IEnumerator MyCoroutine(){
       bool myBool = true;
       System.Action action = ()=&gt;{myBool=false;}
  
       StartCoroutine (MyOtherCoroutine(action));//just launch and forget about it
   }
  
   IEnumerator MyOtherCoroutine(System.Action dangerous_callback){
       yield return null;
       yield return null;//skip several frames
       yield return null;
       dangerous_callback.Invoke();//will cause problems? The owner coroutine (and it's myBool) is no longer on stack
   }
  </code></pre>
  
  <p>My concerns are about <code>myBool</code> that was allocated within the first coroutine. <code>MyCoroutine</code> doesn't wait until <code>MyOtherCoroutine</code> completes. I can see that System.Action won't be collected because it's indeed still referenced by <code>MyOtherCoroutine</code>, but <code>MyCoroutine</code> (whose boolean variable the Action modifies) should have already be deallocated?</p>