From 7e8cf3d458b9c659c221cb8a8bd9a1a9d6b3ffca Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Fri, 24 Sep 2021 15:23:23 +0000 Subject: [PATCH] [FIX] web: legacy: no memory leak via owl.qweb Root components register a listener on env.qweb's "update" event (component.ts:constructor). This means that every legacy ComponentWrapper does this and it proved to cause memory leaks. This fix is two fold: - the owlCompatibility code unregisters the handler on destroy, so that the production run is not impacted by the leak. - the legacy test infrastructure also forces the unregistration. This is necessary because even though components are destroyed, the qweb singleton in legacy tests holds on to destroyed components' reference. closes odoo/odoo#77285 X-original-commit: 89034cf597a418bfd35fdd71324415cdbf046a16 Signed-off-by: Aaron Bohy (aab) --- addons/web/static/src/legacy/js/owl_compatibility.js | 1 + addons/web/static/tests/legacy/helpers/test_env.js | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/addons/web/static/src/legacy/js/owl_compatibility.js b/addons/web/static/src/legacy/js/owl_compatibility.js index e1c82cd3468..9afa2b49685 100644 --- a/addons/web/static/src/legacy/js/owl_compatibility.js +++ b/addons/web/static/src/legacy/js/owl_compatibility.js @@ -343,6 +343,7 @@ odoo.define('web.OwlCompatibility', function () { */ destroy() { for (const component of children.get(this) || []) { + component.env.qweb.off("update", component); component.__destroy(); } children.delete(this); diff --git a/addons/web/static/tests/legacy/helpers/test_env.js b/addons/web/static/tests/legacy/helpers/test_env.js index ff6c0bf6b29..e335d59616a 100644 --- a/addons/web/static/tests/legacy/helpers/test_env.js +++ b/addons/web/static/tests/legacy/helpers/test_env.js @@ -4,6 +4,7 @@ odoo.define('web.test_env', async function (require) { const Bus = require('web.Bus'); const { buildQuery } = require('web.rpc'); const session = require('web.session'); + const { registerCleanup } = require("@web/../tests/helpers/cleanup"); let qweb; @@ -22,6 +23,9 @@ odoo.define('web.test_env', async function (require) { // time and they never change qweb = new owl.QWeb({ templates: session.owlTemplates }); } + registerCleanup(() => { + qweb.subscriptions = {}; + }); const defaultTranslationParamters = { code: "en_US",