From a39e703a2ebd6b36c4463d1abcd81eb4dfa2eb73 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Fri, 23 Dec 2022 09:46:01 +0000 Subject: [PATCH] [FIX] web: remove memory leak with bootstrap tooltips This commit fixes a memory leak occurring in basic renderers. It seems that the issue comes from bootstrap 5.1 (might be fixed in 5.2). As this is legacy code, and updating from 5.1 to 5.2 doesn't seem easy (moreover in stable), we come with a simple and local patch in BasicRenderer. X-original-commit: 3c01b1cd77adec146b1a90f96bb1223a2108678b Part-of: odoo/odoo#108620 Co-authored-by: Samuel Degueldre --- .../static/src/legacy/js/views/basic/basic_renderer.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/addons/web/static/src/legacy/js/views/basic/basic_renderer.js b/addons/web/static/src/legacy/js/views/basic/basic_renderer.js index f2a19a0ca6f..95a227ffa03 100644 --- a/addons/web/static/src/legacy/js/views/basic/basic_renderer.js +++ b/addons/web/static/src/legacy/js/views/basic/basic_renderer.js @@ -47,11 +47,19 @@ var BasicRenderer = AbstractRenderer.extend(WidgetAdapterMixin, { // and on which field it is set. this.handleField = null; this.viewEditable = params.viewEditable; + + // There an issue with bootstrap 5.1 (probably fixed in 5.2). A reference + // to some nodes with attached tooltips are kept and can never be garbage collected. + // We thus manually dispose them at destroy. + this.jQueryNodesWithTooltip = []; }, /** * @override */ destroy: function () { + for (const $node of this.jQueryNodesWithTooltip) { + $node.tooltip("dispose"); + } this._super.apply(this, arguments); WidgetAdapterMixin.destroy.call(this); }, @@ -315,6 +323,8 @@ var BasicRenderer = AbstractRenderer.extend(WidgetAdapterMixin, { // widget's $el $node = $node.length ? $node : widget.$el; $node.tooltip(this._getTooltipOptions(widget)); + + this.jQueryNodesWithTooltip.push($node); }, /** * Does the necessary DOM updates to match the given modifiers data. The