From 4b2b85bd12e9489a30c4f5caf661f0324c09d96b Mon Sep 17 00:00:00 2001 From: Vishal Malyan <146833908+vishal2005025@users.noreply.github.com> Date: Wed, 17 Dec 2025 03:22:24 +0530 Subject: [PATCH] fix(avatar) fix memory leak in preloadImage --- .../base/participants/preloadImage.web.ts | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/react/features/base/participants/preloadImage.web.ts b/react/features/base/participants/preloadImage.web.ts index 7a5f6d9e6a..682a317e3e 100644 --- a/react/features/base/participants/preloadImage.web.ts +++ b/react/features/base/participants/preloadImage.web.ts @@ -22,17 +22,35 @@ export function preloadImage( return new Promise((resolve, reject) => { const image = document.createElement('img'); + // Cleanup function to release resources and prevent memory leaks + const cleanup = () => { + // Clear event handlers to break circular references + image.onload = null; + image.onerror = null; + + // Clear src to stop any pending load and allow GC + image.src = ''; + }; + if (useCORS) { image.setAttribute('crossOrigin', ''); } - image.onload = () => resolve({ - src, - isUsingCORS: useCORS - }); + + image.onload = () => { + cleanup(); + resolve({ + src, + isUsingCORS: useCORS + }); + }; + image.onerror = error => { + cleanup(); + if (tryOnce) { reject(error); } else { + // Retry with different CORS mode preloadImage(src, !useCORS, true) .then(resolve) .catch(reject);