GWT - 是否手动删除 detach/unload 上必需的本机事件处理程序?

GWT - Is manually removing the native events handlers necessary on detach/unload?

如果小部件被添加到面板 (DOM) 以及本机处理程序(例如 ClickHanlder 或 MouseDownHandler),但没有保留对它们的引用,是否需要手动从注册中删除处理程序detach/unload 避免内存泄漏或内存管理不当?

示例:

//at first, somewhere locally
Button b = new Button("My button");
b.addClickHandler(new ClickHandler(){...}) // or just (event -> {do stuff here})
globalPanel.add(b); //some generic scope panel

//later that evening...
globalPanel.clear();
//then maybe do other similar stuff, adding widgets and handlers, repeatedly 

那么是否需要保留处理程序注册并在其他 onDetach/onUnload 调用中将其删除?因为在这种情况下,没有为按钮 "b" 或点击处理程序保留引用。

谢谢。

您不需要删除处理程序。

GWT 实际上做的更多,它使用位域来接收 DOM 事件来修复一些旧浏览器的循环引用问题。虽然现在它没用了,但所有浏览器都能正确处理循环引用。更多信息在此 >10 years old article