From 2b21bdf4e1544999406be21291b328561a6e9981 Mon Sep 17 00:00:00 2001 From: Bogdan Matei Date: Thu, 19 Jun 2025 11:47:03 +0300 Subject: [PATCH] VizTooltip: Fix memory leak (#106907) VizTooltip: Fix memory leak --- .../src/components/uPlot/plugins/TooltipPlugin2.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/grafana-ui/src/components/uPlot/plugins/TooltipPlugin2.tsx b/packages/grafana-ui/src/components/uPlot/plugins/TooltipPlugin2.tsx index b9e3d01b2ac..e19a6230cec 100644 --- a/packages/grafana-ui/src/components/uPlot/plugins/TooltipPlugin2.tsx +++ b/packages/grafana-ui/src/components/uPlot/plugins/TooltipPlugin2.tsx @@ -144,6 +144,8 @@ export const TooltipPlugin2 = ({ getLinksRef.current = getDataLinks; useLayoutEffect(() => { + sizeRef.current?.observer.disconnect(); + sizeRef.current = { width: 0, height: 0, @@ -646,6 +648,8 @@ export const TooltipPlugin2 = ({ window.addEventListener('scroll', onscroll, true); return () => { + sizeRef.current?.observer.disconnect(); + window.removeEventListener('resize', updateWinSize); window.removeEventListener('scroll', onscroll, true); @@ -659,6 +663,7 @@ export const TooltipPlugin2 = ({ const size = sizeRef.current!; if (domRef.current != null) { + size.observer.disconnect(); size.observer.observe(domRef.current); // since the above observer is attached after container is in DOM, we need to manually update sizeRef