diff --git a/cptr/frontend/src/lib/components/Settings/Account.svelte b/cptr/frontend/src/lib/components/Settings/Account.svelte index 8682491..acb80a9 100644 --- a/cptr/frontend/src/lib/components/Settings/Account.svelte +++ b/cptr/frontend/src/lib/components/Settings/Account.svelte @@ -63,7 +63,9 @@ function resizeImage(file: File): Promise { return new Promise((resolve, reject) => { const img = new Image(); + const url = URL.createObjectURL(file); img.onload = () => { + URL.revokeObjectURL(url); const canvas = document.createElement('canvas'); canvas.width = 256; canvas.height = 256; @@ -80,8 +82,11 @@ 'image/png' ); }; - img.onerror = () => reject(new Error('Failed to load image')); - img.src = URL.createObjectURL(file); + img.onerror = () => { + URL.revokeObjectURL(url); + reject(new Error('Failed to load image')); + }; + img.src = url; }); } diff --git a/cptr/frontend/src/lib/components/Terminal.svelte b/cptr/frontend/src/lib/components/Terminal.svelte index 95f78ba..12ef07b 100644 --- a/cptr/frontend/src/lib/components/Terminal.svelte +++ b/cptr/frontend/src/lib/components/Terminal.svelte @@ -62,6 +62,7 @@ let fitAddon: FitAddon | null = null; let ws: WebSocket | null = null; let resizeObserver: ResizeObserver | null = null; + let themeObserver: MutationObserver | null = null; let resizeTimeout: ReturnType | null = null; let reconnectTimer: ReturnType | null = null; let destroyed = false; @@ -262,12 +263,12 @@ }); // Watch for theme changes - const observer = new MutationObserver(() => { + themeObserver = new MutationObserver(() => { if (term) { term.options.theme = terminalTheme(); } }); - observer.observe(document.documentElement, { + themeObserver.observe(document.documentElement, { attributes: true, attributeFilter: ['class', 'style'] }); @@ -506,8 +507,14 @@ if (reconnectTimer) clearTimeout(reconnectTimer); if (hapticTimer) clearTimeout(hapticTimer); resizeObserver?.disconnect(); + themeObserver?.disconnect(); releaseWakeLock(); - ws?.close(); + if (ws) { + ws.onmessage = null; + ws.onclose = null; + ws.onerror = null; + ws.close(); + } term?.dispose(); }); diff --git a/cptr/frontend/src/lib/components/chat/ChatPanel.svelte b/cptr/frontend/src/lib/components/chat/ChatPanel.svelte index 6e38f08..77503f0 100644 --- a/cptr/frontend/src/lib/components/chat/ChatPanel.svelte +++ b/cptr/frontend/src/lib/components/chat/ChatPanel.svelte @@ -1721,6 +1721,11 @@ showTtsFailure(err?.message || 'playback failed'); } } finally { + if (generation === ttsGeneration && ttsObjectUrl) { + URL.revokeObjectURL(ttsObjectUrl); + ttsObjectUrl = null; + } + if (generation === ttsGeneration) ttsAudio = null; if (generation === ttsGeneration) ttsPlaying = false; if (generation === ttsGeneration) speakingMessageId = null; if (generation === ttsGeneration) ttsStopRequested = false;