Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
所以我们知道,如果您附加了一个事件处理程序,如果该对象不再被使用,我们应该在某个时候将其删除。这对 Window 对象有什么作用?
以Window的Loaded事件或Closing事件为例。如果我们在方法中注册 EventHandler 来处理这些事件Initialize,为什么我们不注销它们呢?
Loaded
Closing
Initialize
因为这没什么大不了的。通常您在派生类本身中订阅事件,因此您不会因为杂散事件处理程序订阅而导致实例在内存中逗留。此外,您将需要Closing事件处理程序,直到 Window 的生命周期结束,取消订阅它是没有意义的。