The official UI5 documentation 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.
I've set a break point on this._helloDialog.destroy();
inside of
exit() {
this._helloDialog.destroy();
delete this._helloDialog;
}
And I expect that the break point will be triggered on leaving the view, which hosts this dialog. In fact, when I switched the view nothing happened, it looks like exit()
wasn't executed at all.
Besides that, I've paid attention that after opening the dialog, typing a text there, closing and then reopening the dialog, the previously typed text remains untouched.
Such behavior forces me to assume that the dialog object is never released and it might be a potential place for the memory leak.
My questions:
Why the
exit
hook is not triggered when I leave the view, where this dialog had been defined?Are there any best practices / common patterns for «resetting» the dialog's content in UI5?