Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

fix(windows): release the allocator thread-heap at thread exit

Martin Vogel66c32a81ca68
diff --git a/src/foundation/compat_thread.c b/src/foundation/compat_thread.c
index 5ee8a0478..ffcaab85e 100644
--- a/src/foundation/compat_thread.c
+++ b/src/foundation/compat_thread.c
@@ -30,6 +30,17 @@ static DWORD WINAPI win_thread_wrapper(LPVOID lpParam) {
void *arg = a->arg;
free(a);
fn(arg);
+ /* Release this thread's allocator heap before the thread dies.
+ *
+ * On POSIX a pthread TSD destructor calls this for us, which is why POSIX
+ * stays flat. A static MinGW link has no DllMain and registers no TLS
+ * callback, so nothing runs at thread exit and every thread leaves its
+ * thread-heap behind for the life of the process: 607 heaps after 300
+ * requests, 170 MiB committed against a live set of ~300 KiB, growing
+ * without bound (#581). The heaps are invisible to mi_heap_visit -- which
+ * only sees the main and calling heaps -- which is why the growth looked
+ * like it belonged to no allocator at all. */
+ mi_thread_done();
return 0;
}