Do event handlers stop garbage collection from occurring?

后端 未结 4 1538
离开以前
离开以前 2020-11-22 06:01

If I have the following code:

MyClass pClass = new MyClass();
pClass.MyEvent += MyFunction;
pClass = null;

Will pClass be garbage collected

4条回答
  •  眼角桃花
    2020-11-22 06:16

    pClass will be garbage collected. However, if the code snippet above is inside another class, the instance of that class might not be cleared if you do not set pClass to null.

提交回复
热议问题