From e67c34854f0d0bc8b4ca9839a4d50c8d5cb495a0 Mon Sep 17 00:00:00 2001 From: karl-barkmann Date: Sun, 7 Apr 2024 17:06:03 +0800 Subject: [PATCH] fix: fix memory leak due to invalid image src --- src/graphic/helper/image.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/graphic/helper/image.ts b/src/graphic/helper/image.ts index 858964056..846067529 100644 --- a/src/graphic/helper/image.ts +++ b/src/graphic/helper/image.ts @@ -13,6 +13,7 @@ type PendingWrap = { type CachedImageObj = { image: ImageLike + loading: boolean pending: PendingWrap[] } @@ -62,7 +63,7 @@ export function createOrUpdateImage( if (cachedImgObj) { image = cachedImgObj.image; - !isImageReady(image) && cachedImgObj.pending.push(pendingWrap); + cachedImgObj.loading && cachedImgObj.pending.push(pendingWrap); } else { image = platformApi.loadImage( @@ -74,6 +75,7 @@ export function createOrUpdateImage( newImageOrSrc, (image as any).__cachedImgObj = { image: image, + loading: true, pending: [pendingWrap] } ); @@ -89,6 +91,7 @@ export function createOrUpdateImage( function imageOnLoad(this: any) { const cachedImgObj = this.__cachedImgObj; + cachedImgObj.loading = false; this.onload = this.onerror = this.__cachedImgObj = null; for (let i = 0; i < cachedImgObj.pending.length; i++) {