mirror of
https://gitcode.com/GitHub_Trending/ji/jitsi-meet.git
synced 2025-12-30 11:22:31 +00:00
fix(avatar) fix memory leak in preloadImage
This commit is contained in:
@@ -22,17 +22,35 @@ export function preloadImage(
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const image = document.createElement('img');
|
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) {
|
if (useCORS) {
|
||||||
image.setAttribute('crossOrigin', '');
|
image.setAttribute('crossOrigin', '');
|
||||||
}
|
}
|
||||||
image.onload = () => resolve({
|
|
||||||
src,
|
image.onload = () => {
|
||||||
isUsingCORS: useCORS
|
cleanup();
|
||||||
});
|
resolve({
|
||||||
|
src,
|
||||||
|
isUsingCORS: useCORS
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
image.onerror = error => {
|
image.onerror = error => {
|
||||||
|
cleanup();
|
||||||
|
|
||||||
if (tryOnce) {
|
if (tryOnce) {
|
||||||
reject(error);
|
reject(error);
|
||||||
} else {
|
} else {
|
||||||
|
// Retry with different CORS mode
|
||||||
preloadImage(src, !useCORS, true)
|
preloadImage(src, !useCORS, true)
|
||||||
.then(resolve)
|
.then(resolve)
|
||||||
.catch(reject);
|
.catch(reject);
|
||||||
|
|||||||
Reference in New Issue
Block a user