我有以下類以下方法:靜態方法內存消耗
public class Foo
{
public string A {get;set;}
public static Foo New(string a)
{
Foo newFoo = new Foo();
newFoo.A = a;
return newFoo;
}
}
public class Bar
{
public void SomeMethod()
{
...
Foo anotherFoo = Foo.New("a");
....
}
}
如果酒吧上課期間使用上面的代碼進程創建富,將富曾經走出去的範圍,讓垃圾收集或將Foo(因爲它使用靜態方法)繼續引用變量newFoo,因此anotherFoo永遠不會超出範圍?