From 668f1061d9a7de784f90a0aff548e7af39fe52e2 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 29 Nov 2025 00:26:21 +0000 Subject: [PATCH] Clean up object URL after extracting skin sprites After sprites are extracted from the image via getSpriteUrisFromImg (which draws to canvas and creates data URLs), the original image and its object URL are no longer needed. Clean up the object URL at this point to prevent memory leaks. This only affects the fallback path (HTMLImageElement) since ImageBitmap doesn't have a src property and doesn't use object URLs. --- packages/webamp/js/skinParserUtils.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/webamp/js/skinParserUtils.ts b/packages/webamp/js/skinParserUtils.ts index 5efac9f1..cdda06b2 100644 --- a/packages/webamp/js/skinParserUtils.ts +++ b/packages/webamp/js/skinParserUtils.ts @@ -56,10 +56,7 @@ export async function getFileFromZip( } function fallbackGetImgFromBlob(blob: Blob): Promise { - // Note: We cannot revoke the object URL here because the returned image - // element needs the URL to remain valid for its lifetime. This is an - // acceptable small leak since skin images are loaded infrequently and - // the primary path uses createImageBitmap which doesn't have this issue. + // Create object URL that will be cleaned up after the image is used return Utils.imgFromUrl(URL.createObjectURL(blob)); } @@ -129,7 +126,17 @@ export async function getSpriteUrisFromFilename( if (img == null) { return {}; } - return getSpriteUrisFromImg(img, SKIN_SPRITES[fileName]); + + // Extract sprites from the image + const sprites = getSpriteUrisFromImg(img, SKIN_SPRITES[fileName]); + + // Clean up object URL if the image is an HTMLImageElement with a blob URL + // (ImageBitmap doesn't have a src property, so this only affects the fallback path) + if (img instanceof HTMLImageElement && img.src.startsWith("blob:")) { + URL.revokeObjectURL(img.src); + } + + return sprites; } // https://docs.microsoft.com/en-us/windows/win32/xaudio2/resource-interchange-file-format--riff-