Skip to main content

on_thread_idle

Function on_thread_idle 

Source
pub fn on_thread_idle()
Expand description

Tell mimalloc this thread is idle (issue #272, Bun parity P7a).

Collects this thread’s pending frees, discards the free blocks inside its still-used pages, and hands the arena purge to the background scavenger thread so freed memory returns to the OS now instead of at the next allocation that happens to run a purge – which, on a genuinely idle process, is never.

Safe on any thread; a no-op on a thread that never allocated. Call it when the thread has nothing to do (an event loop about to block, a worker pool waiting on its queue), not on a hot path: it costs a few madvise/DiscardVirtualMemory calls.