离开视图时,基于片段的对话框在 UI5 中不是 destroyed/reset
A fragment-based Dialog is not destroyed/reset in UI5 upon leaving the view
UI5官方文档claims:
[...] We want to make sure that the memory allocated for this helper object is freed up when the component is destroyed. Otherwise our application may cause memory leaks.
To do so, we use the exit
hook. The OpenUI5 framework calls the function assigned to exit
when destroying the component. We call the destroy function of HelloDialog
to clean up the helper class and end its lifecycle. Nevertheless, the instance itself would still exist in the browser memory. Therefore we delete our reference to the HelloDialog
instance by calling delete this._helloDialog
and the garbage collection of the browser can clean up its memory.
我在
里面的this._helloDialog.destroy();
设置了一个断点
exit() {
this._helloDialog.destroy();
delete this._helloDialog;
}
而且我希望在离开承载此对话框的视图时触发断点。事实上,当我切换视图时什么也没有发生,看起来 exit()
根本没有被执行。
除此之外,我注意到在打开对话框、在那里输入文本、关闭然后重新打开对话框后,之前输入的文本保持不变。
这种行为迫使我假设对话框对象永远不会被释放,它可能是内存泄漏的潜在位置。
问题:
- 为什么当我离开定义此对话框的视图时未触发
exit
挂钩?
- 在 UI5 中“重置”对话框的内容是否有任何最佳实践/通用模式?
Why the exit
hook is not triggered when I leave the view, where this dialog had been defined?
销毁对话框一直是一种有问题的做法:例如,当用户决定再次打开它时;对话框及其整个子节点树需要在 DOM 上重新创建和重新呈现,Core 上的每个控件都需要 re-registered,以及它们在 UIArea 上的事件,模型需要要传播同时触发各种事件,内存需要 re-allocated,等等。总而言之 - 它非常昂贵。
exit
-挂钩 然而,当应用程序调用 ManagedObject 上的 destroy()
时,会自动触发。例如,当用户导航到 Home 时,Fiori Launchpad 会自动调用 currentUIComponent.destroy()
,触发每个子元素(包括对话框)上的 exit
-hook。
Are there any best practices / common patterns for «resetting» the dialog's content in UI5?
是的,请参阅我在 上的回答。
UI5官方文档claims:
[...] We want to make sure that the memory allocated for this helper object is freed up when the component is destroyed. Otherwise our application may cause memory leaks.
To do so, we use the
exit
hook. The OpenUI5 framework calls the function assigned toexit
when destroying the component. We call the destroy function ofHelloDialog
to clean up the helper class and end its lifecycle. Nevertheless, the instance itself would still exist in the browser memory. Therefore we delete our reference to theHelloDialog
instance by callingdelete this._helloDialog
and the garbage collection of the browser can clean up its memory.
我在
里面的this._helloDialog.destroy();
设置了一个断点
exit() {
this._helloDialog.destroy();
delete this._helloDialog;
}
而且我希望在离开承载此对话框的视图时触发断点。事实上,当我切换视图时什么也没有发生,看起来 exit()
根本没有被执行。
除此之外,我注意到在打开对话框、在那里输入文本、关闭然后重新打开对话框后,之前输入的文本保持不变。
这种行为迫使我假设对话框对象永远不会被释放,它可能是内存泄漏的潜在位置。
问题:
- 为什么当我离开定义此对话框的视图时未触发
exit
挂钩? - 在 UI5 中“重置”对话框的内容是否有任何最佳实践/通用模式?
Why the
exit
hook is not triggered when I leave the view, where this dialog had been defined?
销毁对话框一直是一种有问题的做法:例如,当用户决定再次打开它时;对话框及其整个子节点树需要在 DOM 上重新创建和重新呈现,Core 上的每个控件都需要 re-registered,以及它们在 UIArea 上的事件,模型需要要传播同时触发各种事件,内存需要 re-allocated,等等。总而言之 - 它非常昂贵。
exit
-挂钩 destroy()
时,会自动触发。例如,当用户导航到 Home 时,Fiori Launchpad 会自动调用 currentUIComponent.destroy()
,触发每个子元素(包括对话框)上的 exit
-hook。
Are there any best practices / common patterns for «resetting» the dialog's content in UI5?
是的,请参阅我在