Goto main content

help desk

How to clear global listener in order to free the memory usage

if you add a listener on a global level, don't forget to "off" it, otherwise the memory on the FE will grow until a complete reload of the page is done.

Asked on 2022-12-06 06:22:00

OFFICIAL ANSWER

if you add a listener on a global level, don't forget to "off" it, otherwise the memory on the FE will grow until a complete reload of the page is done.

AVOID DOING

// Widget/spa page template
function init(){
 [...]
 $("body").on("click", ...)
 [...]
}

DO INSTEAD

// Widget/spa page template
function init(){
 [...]
 $("body").off("click.unique_namespace").on("click.unique_namespace", ...)
 [...]
}

where "unique_namespace" should be unique in the app. I suggest you use the code of your widget/spa page

Answer by:
Etienne Carrier

Replied on: 2022-12-06 10:35:00