当我在方法中创建对象/变量时,在方法调用之后,所有对象都将被设置为由 GC 收集,并且所有“原始”变量(int、string、decimal ...)都被销毁,对吗?
所以,如果是的话:
public void MyMethod()
{
// Imagine an class that connects with ftp server
MyObject o = new MyObject();
o.Connect();
}
如果我在行中有错误o.Connect()
并且我有一个try
`catch only to log the error,
MyObject o` 将被 GC 收集?