Skip to content

Commit 9b1a54d

Browse files
committed
feat: implement a mark-and-sweep garbage collector for runtime memory management.
1 parent d3b4e7f commit 9b1a54d

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/runtime/gc.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,19 @@ static void freeObject(Obj* object) {
251251
FREE(struct ObjDictionary, object);
252252
break;
253253
}
254+
case OBJ_TASK: {
255+
// coroHandle is void* managed by LLVM/malloc?
256+
// If we used a custom allocator, we free it here.
257+
// But LLVM `coro.destroy` handles it.
258+
// We should call `llvm.coro.destroy(hdl)` if task is dead?
259+
// But we can't easily call LLVM intrinsic from here.
260+
// We assume LLVM code cleaned up via `coro.free` path
261+
// when task reached end.
262+
// If task is collected BEFORE completion, we might leak the coroutine frame.
263+
// For now, simple free of ObjTask struct.
264+
FREE(struct ObjTask, object);
265+
break;
266+
}
254267
default:
255268
FREE(Obj, object); // Fallback
256269
break;

0 commit comments

Comments
 (0)