Skip to content

Commit 9b7b0a5

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 da0a653 commit 9b7b0a5

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
@@ -15,6 +15,14 @@ interface Context {
1515
const context = Context.create<Context>("instance")
1616
const cache = createLruCache<string, Promise<Context>>({
1717
maxEntries: 20,
18+
onEvict: async (_key, value) => {
19+
const ctx = await value.catch(() => null)
20+
if (ctx) {
21+
await context.provide(ctx, async () => {
22+
await State.dispose(ctx.directory)
23+
})
24+
}
25+
},
1826
})
1927

2028
const disposal = {

0 commit comments

Comments
 (0)