Do you need to remove an event handler in the destructor?

后端 未结 9 1258
情书的邮戳
情书的邮戳 2021-01-31 01:22

I use some UserControls which get created and destroyed within my application during runtime (by creating and closing subwindows with these controls inside).
It

9条回答
  •  爱一瞬间的悲伤
    2021-01-31 02:10

    Is PPMM something external with a longer lifetime that the MyControl instances?

    If so, unless PPMM_FactorChanged is a static method, the ppmmEventHandler will be keeping a reference to the MyControl instance live - which means the instance will never be eligible for garbage collection, and the finalizer will never fire.

    You shouldn't need to keep the ppmmEventHandler around for the removal code.

提交回复
热议问题