我有下面描述的课程。GC 是否从类“C”中的对象“a”中收集 field1 和 field2?
public abstract class A
{
//some methods and properties
}
public class B : A
{
public int field1 { get; set; }
public int field2 { get; set; }
}
public class C
{
public A a { get; set; }
private System.Windows.Forms.Timer timer;
public C()
{
a = (A)typeof(B).GetConstructor(bla, bla, bla).Invoke(bla, bla);
((B)a).field1 = 25;
timer = new System.Windows.Forms.Timer();
timer.Enabled = true;
timer.Interval = 10000;
timer.OnTick += (o, e) => { Console.WriteLine(((B)a).field1); };
}
}