Skip to content

Windows overlay private memory grows linearly on repeated keyed subtree mount/unmount and is never reclaimed while visible #1875

Not planned

Description

@rein-77

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 Runtime driving the same view on eb5ae6c (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

  1. Hona commented on Nov 24, 2026

    @Hona
    Member

    On current dev, two separate findings apply:

    1. Idle reclamation on visible overlays is now fixed in fix(overlay): reclaim spare GPU pools and runtime caches while resting #1933 (1d78d56): OverlayCore now runs the same Rest state 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 two Rgba16Float targets used by opacity transitions), unused El::cache textures, 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.
    2. Linear growth did not reproduce off-screen across three Windows DX12 adapters (not claimed fixed): Running the exact panel-0/panel-1 Transition::opacity() swap view vs. the static control off-screen (Gpu::headless, Offscreen, Renderer, Runtime) for 1,000 flips (~25 frames/flip at dt = 1/60 s) with --features rune/alloc-sites,rune/test-gpu-counters and procwatch::alloc::Counting showed 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) and generate_allocator_report() across flips 50–1,000 (950 flips):
    Adapter (DX12) Mode PrivateUsage Δ (50→1000) Rust heap Δ HAL & allocator Δ layer_stats.allocations
    NVIDIA GeForce RTX 5070 Ti (32.0.16.1742) swap 1x / 2x / 50-child −6,888 / −76 / +40 KiB +20.4 / 0.0 / 0.0 KiB 0 2
    NVIDIA GeForce RTX 5070 Ti (32.0.16.1742) static 1x / 2x +1,724 / +900 KiB +0.3 / −1.2 KiB 0 0
    AMD Radeon Graphics (32.0.21045.5002) swap 1x / 2x / 50-child −108 / +4 / +20 KiB 0.0 / 0.0 / 0.0 KiB 0 2
    AMD Radeon Graphics (32.0.21045.5002) static 1x / 2x +20 / −20 KiB 0.0 / −0.8 KiB 0 0
    Microsoft Basic Render Driver / WARP (10.0.26100.9818) swap 1x / 2x / 50-child +2,444* / −860 / +2,152* KiB 0.0 / 0.0 / 0.0 KiB 0 2
    Microsoft Basic Render Driver / WARP (10.0.26100.9818) static 1x / 2x +1,848 / +1,320 KiB 0.0 / −1.2 KiB 0 0

    *WARP PrivateUsage fluctuated within ~2 MiB and fell back down after peaking mid-run (e.g. swap 1x peaked at 83,108 KiB at flip 500 and ended at 81,276 KiB at flip 1,000), matching the static control rather than growing linearly.

    Because Rune's heap and GPU objects do not grow in this path on these adapters, the linear PrivateUsage growth 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 current dev (1d78d56 or later), please reopen with two captures from overlay_swap_leak -- swap 240 built with --features rune/alloc-sites (using procwatch::alloc::Counting as #[global_allocator] and PROCWATCH_ALLOC_SITES=<dir>, signaling Local\procwatch-alloc-sites-<pid> at t = 30 s and t = 210 s to record PrivateUsage, Rust heap sites, rune-gpu, and gpu HAL/allocator counters):

    1. On the default Intel Iris Xe adapter with RUNE_GPU_LOG=1.
    2. With WGPU_ADAPTER_NAME="Microsoft Basic Render Driver" and RUNE_GPU_LOG=1.

    Thanks for the detailed repro and measurements.

  2. rein-77 commented on Nov 25, 2026

    @rein-77
    Author

    Follow-up: this was the Intel driver. After updating Intel Iris Xe from 30.0.100.9864 (2021-08-20) to 32.0.101.7092 (2026-09-03), the same overlay_swap_leak -- swap 240 run is flat:

    Build Old driver 30.0.100.9864 New driver 32.0.101.7092
    dev 766c7f39, swap +6,748 KiB over 300 flips (t = 30 s → end), linear 72,244 → 72,816 KiB (t = 60 s → 210 s), flat; −2,436 KiB after 20 s idle
    dev 766c7f39, static flat flat
    eb5ae6c, same swap scene ~3.06 MB/min, linear +1 MB warm-up, then flat from t = 90 s

    With the old driver, the alloc-sites captures 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 all gpu / rune-gpu counters 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions