Eclipse RCP: How and when to correctly unsubscribe a Composite from EventBroker?

蹲街弑〆低调 提交于 2020-01-15 15:28:54

问题


In the constructor of my custom composite (inherited from SWT Composite), I register myself as an EventHandler to the Eclipse IEventBroker.

To unsubscribe upon disposal, I had overridden the dispose method where I unsubscribe myself.

But I now noticed that this unsubscription is not happening, indeed the dispose method is never getting called.

What is the correct way to unsubscribe myself, or to avoid that a closed Composite/ViewPart leaves "leaking" event handlers behind?

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.


回答1:


Use the addDisposeListener of the Composite to add a DisposeListener and do the unsubscribe in the listener.



来源:https://stackoverflow.com/questions/30625525/eclipse-rcp-how-and-when-to-correctly-unsubscribe-a-composite-from-eventbroker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!