在协程中调用声明的 System.Action 是安全的吗?
我的担忧是关于在第一个协程中分配的`myBool`。`MyCoroutine`不会等待`MyOtherCoroutine`完成。我可以看到`System.Action`不会被回收,因为它确实仍然被`MyOtherCoroutine`引用,但是`MyCoroutine`(其布尔变量由该Action修改)应该已经被释放了吗?
IEnumerator MyCoroutine(){
bool myBool = true;
System.Action action = ()=>{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
}
我的担忧是关于在第一个协程中分配的`myBool`。`MyCoroutine`不会等待`MyOtherCoroutine`完成。我可以看到`System.Action`不会被回收,因为它确实仍然被`MyOtherCoroutine`引用,但是`MyCoroutine`(其布尔变量由该Action修改)应该已经被释放了吗?