问题描述
在自定义组合的构造函数中(继承自SWT Composite
),我将自己注册为Eclipse IEventBroker
的EventHandler.
In the constructor of my custom composite (inherited from SWT Composite
), I register myself as an EventHandler to the Eclipse IEventBroker
.
要取消订阅,我已经在自己取消订阅的地方覆盖了 dispose
方法.
To unsubscribe upon disposal, I had overridden the dispose
method where I unsubscribe myself.
但是我现在注意到取消订阅没有发生,实际上从未调用过 dispose
方法.
But I now noticed that this unsubscription is not happening, indeed the dispose
method is never getting called.
退订自己或避免关闭的Composite/ViewPart留下泄漏"事件处理程序的正确方法是什么?
What is the correct way to unsubscribe myself, or to avoid that a closed Composite/ViewPart leaves "leaking" event handlers behind?
我使用Eclipse RCP 3.x(因此没有注释/注入).在E4中,如果我理解正确的话,可以使用自动事件订阅或@Predestroy方法.
I use Eclipse RCP 3.x (so no annotations/injection). In E4 I could use the automatic Event subscription or the @Predestroy method, if I understood it correctly.
推荐答案
使用 Composite
的 addDisposeListener
添加 DisposeListener
并执行取消订阅侦听器.
Use the addDisposeListener
of the Composite
to add a DisposeListener
and do the unsubscribe in the listener.
这篇关于Eclipse RCP:如何以及何时正确地从EventBroker取消订阅Composite?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!