Skip to content

Commit 18e135d

Browse files
committed
feat: added memory cleanup.
1 parent e659343 commit 18e135d

3 files changed

Lines changed: 9 additions & 2 deletions

File tree

platforms/metagram/src/lib/fragments/BottomNav/BottomNav.svelte

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { Camera, CommentsTwo, Home, Search } from '$lib/icons';
55
import { isNavigatingThroughNav, ownerId } from '$lib/store/store.svelte';
66
import { uploadedImages } from '$lib/store/store.svelte';
7+
import { revokeImageUrls } from '$lib/utils';
78
import type { HTMLAttributes } from 'svelte/elements';
89
910
interface IBottomNavProps extends HTMLAttributes<HTMLElement> {
@@ -45,6 +46,8 @@
4546
$effect(() => {
4647
activeTab = _activeTab.split('/').pop() ?? '';
4748
if (images && images.length > 0 && activeTab !== 'post' && previousTab === 'post' && !_activeTab.includes('post/audience')) {
49+
if (uploadedImages.value)
50+
revokeImageUrls(uploadedImages.value);
4851
uploadedImages.value = Array.from(images).map(file => ({
4952
url: URL.createObjectURL(file),
5053
alt: file.name
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Image } from "$lib/types";
22

3-
export const revokeImageUrls = (imageArray: Image) => {
3+
export const revokeImageUrls = (imageArray: Image[]) => {
44
imageArray?.forEach((img) => URL.revokeObjectURL(img.url));
55
};

platforms/metagram/src/routes/(protected)/post/+page.svelte

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { SettingsTile, UploadedPostView } from '$lib/fragments';
44
import { audience, uploadedImages } from '$lib/store/store.svelte';
55
import { Button, Textarea } from '$lib/ui';
6+
import { revokeImageUrls } from '$lib/utils';
67
78
let caption: string = $state('');
89
@@ -20,7 +21,10 @@
2021
height="h-40"
2122
callback={(i: number) => {
2223
if (uploadedImages.value)
23-
uploadedImages.value = uploadedImages.value.filter((_, index) => index !== i);
24+
uploadedImages.value = uploadedImages.value.filter((img, index) => {
25+
revokeImageUrls([img]);
26+
return index !== i
27+
});
2428
}}
2529
/>
2630

0 commit comments

Comments
 (0)