我想知道在这些情况下何时调用析构函数,如果是,它会在主 UI 线程上调用吗?
假设我有以下代码,什么时候调用析构函数,它会等到我完成所有函数调用吗?
private void Foo()
{
MyObject myObj = new MyObject();
DoSomeFunThingsWithMyObject(myObj);
myObj = new MyObject(); //is the destructor for the first instance called now?
DoLongOminousFunctionality(myObj);
}
//Or will it be called after the DoLongOminousFunctionality?
如果线程在 myObj = new MyObject() 处被中断,或者如果析构函数调用等待线程空闲,这只是我感兴趣的事情。
谢谢你提供的详情。