[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) <aab@odoo.com>
This commit is contained in:
Lucas Perais (lpe)
2021-09-28 06:48:40 +00:00
parent 56a35fc294
commit 7e8cf3d458
2 changed files with 5 additions and 0 deletions
@@ -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);
@@ -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",