Skip to content

Commit 589ec15

Browse files
fix: prevent memory leaks in clearApiCache
1 parent 02bca04 commit 589ec15

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Diff for: src/lib/py/api.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import type { PyCallable, PyProxy } from "pyodide/ffi";
2+
13
import { py } from "./load";
24

3-
const cache = new Map<string, any>();
5+
const cache = new Map<string, PyProxy>();
46

5-
export function getApi<T = () => any>(slug: string): T {
7+
export function getApi<T extends PyCallable>(slug: string): T {
68
if (cache.has(slug)) {
79
return cache.get(slug) as T;
810
} else {
@@ -13,5 +15,6 @@ export function getApi<T = () => any>(slug: string): T {
1315
}
1416

1517
export function clearApiCache() {
18+
cache.forEach(value => value.destroy());
1619
cache.clear();
1720
}

0 commit comments

Comments
 (0)