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