C# - anonymous functions and event handlers

后端 未结 4 593
情深已故
情深已故 2021-02-02 10:50

I have the following code:

public List FindStepsByType(IWFResource res)  
{  
    List retval = new List&         


        
4条回答
  •  粉色の甜心
    2021-02-02 11:05

    No, it will not be removed automatically. In this sense, there's not a difference between an anonymous method and a "normal" method. If you want, you should manually unsubscribe from the event.

    Actually, it'll capture other variables (e.g. res in your example) and keep them alive (prevents garbage collector from collecting them) too.

提交回复
热议问题