Repository navigation
Description
Tested on dev at ac452a9c on Windows 11 Pro (build 26300), Intel Iris Xe Graphics (driver 30.0.100.9864, DX12), rustc 1.99.1, --release. Also reproduced on eb5ae6c.
A visible Overlay whose view swaps one keyed subtree for another (so one unmounts and the other mounts) grows process private memory (PrivateUsage from K32GetProcessMemoryInfo) linearly with the number of swaps. It does not plateau over 4 minutes and nothing is given back after 20 s idle. The same overlay rendering the same changes under one stable key stays flat.
Repro
crates/rune/examples/overlay_swap_leak.rs, run with cargo run --release -p rune --example overlay_swap_leak -- swap 240 and -- static 240. A background thread flips the state every 700 ms. The only difference between the two modes is the panel's key: panel-0/panel-1 (swap) vs panel (static).
overlay_swap_leak.rs (126 lines)
#![allow(unsafe_code)]
//! Windows overlay private memory vs. keyed subtree swaps.
//! `cargo run --release -p rune --example overlay_swap_leak -- swap|static [seconds]`
use rune::{App, AppSpec, Color, El, Spring, SpringPair, Transition, el, text};
use std::time::{Duration, Instant};
#[repr(C)]
#[derive(Default)]
struct Counters {
cb: u32,
page_faults: u32,
sizes: [usize; 8],
private_usage: usize,
}
unsafe extern "system" {
fn GetCurrentProcess() -> *mut core::ffi::c_void;
fn K32GetProcessMemoryInfo(p: *mut core::ffi::c_void, c: *mut Counters, cb: u32) -> i32;
}
fn private_kib() -> usize {
let mut c = Counters {
cb: size_of::<Counters>() as u32,
..Default::default()
};
assert_ne!(
unsafe { K32GetProcessMemoryInfo(GetCurrentProcess(), &mut c, c.cb) },
0
);
c.private_usage / 1024
}
struct State {
swap: bool,
flips: usize,
}
fn view(s: &State, _: &mut rune::Cx<State>) -> El {
let i = s.flips % 2;
// `swap`: a different key each flip, so one panel unmounts and the other mounts.
// `static`: same key, only its fill and text change.
let key = if s.swap {
format!("panel-{i}")
} else {
"panel".into()
};
let fade = Spring::new(0.16, 0.0);
el().size(440.0, 208.0)
.child(
el().absolute(20.0, 0.0)
.size(400.0, 184.0)
.radius(16.0)
.fill(Color::BLACK.alpha(0.9)),
)
.child(
el().key(key)
.absolute(20.0, 0.0)
.size(400.0, 184.0)
.transition(Transition::opacity().springs(SpringPair::new(fade, fade)))
.child(
el().absolute(24.0, 36.0)
.size(352.0, 120.0)
.radius(12.0)
.fill(Color::WHITE.alpha(if i == 0 { 0.12 } else { 0.22 }))
.child(
text(if i == 0 { "Panel Zero" } else { "Panel One" })
.color(Color::WHITE),
),
),
)
}
fn main() {
let mut args = std::env::args().skip(1);
let swap = args.next().as_deref() != Some("static");
let secs: u64 = args.next().and_then(|s| s.parse().ok()).unwrap_or(240);
let mut app = App::new(AppSpec::new(
"overlay-swap-leak",
(1.0, 1.0),
|| (),
|_, _| el(),
))
.windowless();
let quit = app.handle();
let overlay = app.overlay(
rune::OverlaySpec::new("swap leak", (440.0, 208.0), view),
State { swap, flips: 0 },
);
let driver = overlay.clone();
std::thread::spawn(move || {
std::thread::sleep(Duration::from_secs(2));
let start = Instant::now();
let base = private_kib();
println!(
"mode={} baseline={base} KiB",
if swap { "swap" } else { "static" }
);
let mut flips = 0;
while start.elapsed() < Duration::from_secs(secs) {
std::thread::sleep(Duration::from_millis(700));
flips += 1;
driver.update(|s, _| s.flips += 1);
if flips % 43 == 0 {
let now = private_kib();
println!(
"t={:>3}s flips={flips:>3} private={now} KiB delta={:+} KiB",
start.elapsed().as_secs(),
now as i64 - base as i64
);
}
}
let end = private_kib();
std::thread::sleep(Duration::from_secs(20));
let idle = private_kib();
println!(
"end={end} KiB after 20 s idle={idle} KiB ({:+} KiB)",
idle as i64 - end as i64
);
println!(
"total: {flips} flips, {:+} KiB ({:.1} KiB/flip)",
end as i64 - base as i64,
(end as f64 - base as f64) / flips as f64
);
quit.quit();
});
overlay.show();
app.run();
}Results (ac452a9c)
The first sample is taken 2 s after start and includes a start-up peak that falls away, so growth is measured from t = 30 s.
| Mode | t = 30 s | t = 120 s | t = 210 s | End (~240 s) | Growth from 30 s | After 20 s idle |
|---|---|---|---|---|---|---|
swap (343 flips) |
56,396 KiB | 59,204 KiB | 61,788 KiB | 63,196 KiB | +6,800 KiB over 300 flips (~22.7 KiB/flip, ~1.9 MB/min) | +0 KiB |
static (343 flips) |
41,220 KiB | 41,088 KiB | 40,992 KiB | 40,992 KiB | −228 KiB | +0 KiB |
Growth arrives in steps of a few hundred KiB that keep recurring through the whole run. On eb5ae6c the same scene (a separate harness) grew about 3.06 MB/min, in ~268 KiB steps, with the same flat static control. So dev is slower but still linear.
Observations
- A CPU-only
Runtimedriving the same view oneb5ae6c(80 toggles,Runtime::frame) stayed flat (+28 KiB), so the growth appears to be on the GPU/presentation side, not in the element tree. - Animating bars or changing text every frame without mount/unmount plateaus. Growth tracks how many subtrees mount and unmount, and with larger subtrees it is larger per swap.
- Thread and handle counts stay flat throughout.
Impact
A Windows overlay app that pages between a few views (and expands/collapses on hover) gains roughly 10–20 MB per minute of active use and keeps it until the process restarts.
Expected
Private memory plateaus under repeated mount/unmount of a bounded set of subtrees, and memory a removed subtree used is reused or released while the overlay stays visible.
Activity
Hona commentedon Nov 24, 2026
On current
dev, two separate findings apply:1d78d56):OverlayCorenow runs the sameReststate machine as windows (crates/rune/src/window/state/rest.rs,crates/rune/src/overlay/lifetime.rs). After 10 s without drawing (1 s under Windows low-memory pressure), a visible overlay reclaims its spare layer targets (including the twoRgba16Floattargets used by opacity transitions), unusedEl::cachetextures, unused backdrops/blur pyramids, oversized staging chunks, and stale text/image/rewind caches, with zero wakes or frames while idle. Hiding or occluding an overlay that keeps its renderer also releases scratch targets and staging chunks via non-blocking retirement.panel-0/panel-1Transition::opacity()swapview vs. thestaticcontrol off-screen (Gpu::headless,Offscreen,Renderer,Runtime) for 1,000 flips (~25 frames/flip atdt = 1/60 s) with--features rune/alloc-sites,rune/test-gpu-countersandprocwatch::alloc::Countingshowed flat Rust heap and zero growth in all wgpu HAL counters (textures,texture_memory,buffers,buffer_memory,texture_views,bind_groups,command_encoders,memory_allocations) andgenerate_allocator_report()across flips 50–1,000 (950 flips):PrivateUsageΔ (50→1000)layer_stats.allocations32.0.16.1742)swap1x / 2x / 50-child32.0.16.1742)static1x / 2x32.0.21045.5002)swap1x / 2x / 50-child32.0.21045.5002)static1x / 2x10.0.26100.9818)swap1x / 2x / 50-child10.0.26100.9818)static1x / 2x*WARP
PrivateUsagefluctuated within ~2 MiB and fell back down after peaking mid-run (e.g.swap1x peaked at 83,108 KiB at flip 500 and ended at 81,276 KiB at flip 1,000), matching thestaticcontrol rather than growing linearly.Because Rune's heap and GPU objects do not grow in this path on these adapters, the linear
PrivateUsagegrowth appears specific to live DirectComposition presentation and/or the Intel Iris Xe driver (30.0.100.9864), which we cannot reproduce without that hardware. If it still reproduces on currentdev(1d78d56or later), please reopen with two captures fromoverlay_swap_leak -- swap 240built with--features rune/alloc-sites(usingprocwatch::alloc::Countingas#[global_allocator]andPROCWATCH_ALLOC_SITES=<dir>, signalingLocal\procwatch-alloc-sites-<pid>att = 30 sandt = 210 sto recordPrivateUsage, Rust heap sites,rune-gpu, andgpuHAL/allocator counters):RUNE_GPU_LOG=1.WGPU_ADAPTER_NAME="Microsoft Basic Render Driver"andRUNE_GPU_LOG=1.Thanks for the detailed repro and measurements.
rein-77 commentedon Nov 25, 2026
Follow-up: this was the Intel driver. After updating Intel Iris Xe from
30.0.100.9864(2021-08-20) to32.0.101.7092(2026-09-03), the sameoverlay_swap_leak -- swap 240run is flat:30.0.100.986432.0.101.7092dev766c7f39,swapdev766c7f39,staticeb5ae6c, same swap sceneWith the old driver, the
alloc-sitescaptures at t = 30 s and t = 210 s showed the growth entirely in the process default NT heap (+5.8 MB), with the Rust heap (+52 B) and allgpu/rune-gpucounters unchanged. With the new driver that heap no longer grows either. So it was not Rune; nothing to reopen. Thanks for #1933 and for pointing at the driver path.