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 RSS not dropping after delete_project: add mem_collect + immediate purge

Martin Vogeld33b9e45d9b9
diff --git a/src/foundation/mem.c b/src/foundation/mem.c
index 79953ba31..67ef4d14e 100644
--- a/src/foundation/mem.c
+++ b/src/foundation/mem.c
@@ -116,8 +116,12 @@ void cbm_mem_init(double ram_fraction) {
ram_fraction = DEFAULT_RAM_FRACTION;
}
- /* Reduce upfront memory: don't eagerly commit arenas */
+ /* Reduce upfront memory: don't eagerly commit arenas.
+ * Force decommit on purge (MADV_FREE_REUSABLE on macOS) so RSS
+ * drops immediately instead of staying high until memory pressure. */
mi_option_set(mi_option_arena_eager_commit, 0);
+ mi_option_set(mi_option_purge_decommits, SKIP_ONE);
+ mi_option_set(mi_option_purge_delay, 0); /* immediate purge, no 1s delay */
cbm_system_info_t info = cbm_system_info();
g_budget = (size_t)((double)info.total_ram * ram_fraction);
diff --git a/src/mcp/mcp.c b/src/mcp/mcp.c
index 2eb365caa..3372826b5 100644
--- a/src/mcp/mcp.c
+++ b/src/mcp/mcp.c
@@ -1554,6 +1554,7 @@ static char *handle_delete_project(cbm_mcp_server_t *srv, const char *args) {
}
cbm_pipeline_unlock();
+ cbm_mem_collect(); /* return freed pages to OS after closing database */
yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);
yyjson_mut_val *root = yyjson_mut_obj(doc);