From 0ef1b7b8c4e2a453193ddafb4ceaa692e8e65b4f Mon Sep 17 00:00:00 2001 From: Martin Vogel Date: Thu, 19 Mar 2026 22:17:38 +0100 Subject: [PATCH] Release RAM after indexing, static-link Windows binary - Call cbm_mem_collect() (mi_collect(true)) after pipeline_free in both index_repository and auto-index, returning mimalloc pages to OS - Add -static to Windows linker flags so the binary is standalone (no libc++.dll / libunwind.dll dependency) --- Makefile.cbm | 2 +- src/mcp/mcp.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile.cbm b/Makefile.cbm index ddd4ba9bc..666a94551 100644 --- a/Makefile.cbm +++ b/Makefile.cbm @@ -78,7 +78,7 @@ CXXFLAGS_TSAN = $(CXXFLAGS_COMMON) -g -O1 \ IS_MINGW := $(shell echo | $(CC) -dM -E - 2>/dev/null | grep -q 'define _WIN32 ' && echo yes || echo no) WIN32_LIBS := ifeq ($(IS_MINGW),yes) -WIN32_LIBS := -lws2_32 -lpsapi -Wl,--allow-multiple-definition -Wl,--stack,8388608 +WIN32_LIBS := -lws2_32 -lpsapi -Wl,--allow-multiple-definition -Wl,--stack,8388608 -static endif LDFLAGS = -lm -lstdc++ -lpthread -lz $(LIBGIT2_LIBS) $(WIN32_LIBS) diff --git a/src/mcp/mcp.c b/src/mcp/mcp.c index 60a8d120c..3924b8683 100644 --- a/src/mcp/mcp.c +++ b/src/mcp/mcp.c @@ -13,6 +13,7 @@ #include "pipeline/pipeline.h" #include "cli/cli.h" #include "watcher/watcher.h" +#include "foundation/mem.h" #include "foundation/platform.h" #include "foundation/compat.h" #include "foundation/compat_fs.h" @@ -1230,6 +1231,7 @@ static char *handle_index_repository(cbm_mcp_server_t *srv, const char *args) { * No need to close srv->store — pipeline doesn't touch the open store. */ int rc = cbm_pipeline_run(p); cbm_pipeline_free(p); + cbm_mem_collect(); /* return mimalloc pages to OS after large indexing */ /* Invalidate cached store so next query reopens the fresh database */ if (srv->owns_store && srv->store) { @@ -2128,6 +2130,7 @@ static void *autoindex_thread(void *arg) { int rc = cbm_pipeline_run(p); cbm_pipeline_free(p); + cbm_mem_collect(); /* return mimalloc pages to OS after indexing */ if (rc == 0) { cbm_log_info("autoindex.done", "project", srv->session_project);