diff --git a/apps/ai-game-creator-shell/src/components/game-distribution/useGameDistributionPublishForm.ts b/apps/ai-game-creator-shell/src/components/game-distribution/useGameDistributionPublishForm.ts index f890bb928..3584d74f1 100644 --- a/apps/ai-game-creator-shell/src/components/game-distribution/useGameDistributionPublishForm.ts +++ b/apps/ai-game-creator-shell/src/components/game-distribution/useGameDistributionPublishForm.ts @@ -215,6 +215,31 @@ export function useGameDistributionPublishForm({ // 文件签名 → 素材 ID:同一次打开面板重复提交不会重复上传同一张图。 const uploadedAssetCacheRef = useRef(new Map()); const objectUrlsRef = useRef(new Set()); + /** 上一张封面:替换 / 移除 / AI 生成覆盖时用来回收它的预览 blob 地址。 */ + const previousCoverRef = useRef(null); + + /** + * 封面预览地址跟着封面走:换封面、移除封面、AI 生成覆盖都会丢掉上一张的 blob 地址, + * 不在这里统一回收就会一路泄漏到面板卸载(卸载清理只认 `objectUrlsRef`)。 + */ + useEffect(() => { + const previous = previousCoverRef.current; + previousCoverRef.current = cover; + if ( + !previous || + previous === cover || + !previous.previewUrl || + !objectUrlsRef.current.has(previous.previewUrl) + ) { + return; + } + try { + URL.revokeObjectURL(previous.previewUrl); + } catch { + // 预览地址释放失败不影响换封面 / 移除封面。 + } + objectUrlsRef.current.delete(previous.previewUrl); + }, [cover]); useEffect(() => { if (!open) return;