From 70f6678271fbdb4a503dec36081017913faf3718 Mon Sep 17 00:00:00 2001
From: Ivan <87540740+Pecnikas@users.noreply.github.com>
Date: Mon, 30 Nov 2026 21:51:07 +0500
Subject: [PATCH] perf(memory): release freed heap pages after closing a
project or tabs (#7072)
Closing a project or a batch of documents now calls release_free_pages once, 2 s after the last close, on a background thread. On macOS the freed pages are already reclaimable, so the footprint change is within noise; on Linux malloc_trim can return pages glibc would keep resident (not measured).
Co-authored-by: Pecnikas <87540740+Pecnikas@users.noreply.github.com>
---
crates/ide-core/src/memory.rs | 55 ++++++++++++++++++++++++++++++++++
crates/ide-host/src/lib.rs | 2 ++
crates/ide-host/src/ops/doc.rs | 1 +
3 files changed, 58 insertions(+)
diff --git a/crates/ide-core/src/memory.rs b/crates/ide-core/src/memory.rs
index e42e6fd6eb..18d6651b08 100644
--- a/crates/ide-core/src/memory.rs
+++ b/crates/ide-core/src/memory.rs
@@ -1,5 +1,35 @@
//! Returning freed heap pages to the OS.
+use std::sync::Mutex;
+use std::time::{Duration, Instant};
+
+/// Like [`release_free_pages`], on a background thread once 2 s pass without another call:
+/// closing a project or a batch of tabs frees memory in bursts, released once.
+pub fn release_free_pages_soon() {
+ static DUE: Mutex