Dev explicit registration EvenHandler to explicitly write-off to avoid memory leaks

The method registered to a member of an object reference to an event will cause the latter to hold the former. Before the event cancellation, the former will not be garbage.

private void Form1_Load()
{
……
//注册事件
CommandRemotingContext.CmdChanged += new ReciverCmdStateChangedEventHandler(this.CommandRemotingContext_CmdChanged);
……
}
private void Form1_FromClosed()
{
……
//关闭窗体时及时释放事件
CommandRemotingContext.CmdChanged -= new ReciverCmdStateChangedEventHandler(this.CommandRemotingContext_CmdChanged);
……
}

Reproduced in: https: //my.oschina.net/cjkall/blog/195859

Guess you like

Origin blog.csdn.net/weixin_34318956/article/details/91756225