Skip to content

Commit 8472f15

Browse files
committed
fix(instance): Add onEvict callback for proper Instance disposal
When LRU cache evicts an Instance, call State.dispose() to clean up associated resources. Prevents memory leaks from evicted instances.
1 parent 1305489 commit 8472f15

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

packages/opencode/src/project/instance.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ export interface Shape {
1616
const context = Context.create<Shape>("instance")
1717
const cache = createLruCache<string, Promise<Shape>>({
1818
maxEntries: 20,
19+
onEvict: async (_key, value) => {
20+
const ctx = await value.catch(() => null)
21+
if (ctx) {
22+
await context.provide(ctx, async () => {
23+
await State.dispose(ctx.directory)
24+
})
25+
}
26+
},
1927
})
2028

2129
const disposal = {

0 commit comments

Comments
 (0)