Eclipse RCP: How and when to correctly unsubscribe

2019-08-11 17:34发布

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条回答
对你真心纯属浪费
2楼-- · 2019-08-11 18:06

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

查看更多
登录 后发表回答