Skip to content

A hidden window keeps the Pixels of its last view after the app drops them #2675

Done

Description

@godismyjudge95

What happens

A hidden window keeps the view it built last. Its elements hold clones of each Pixels they showed. A hidden window builds no new view (runtime/drop_tests.rs#L120: "While covered, the window builds nothing"; runtime/api.rs#L73-L76). So when the app drops its own Pixels while the window is hidden, Rune still holds them until the window shows again.

These held images also keep their image atlas pages on the CPU side (#163), so the cost is about two times the image size.

Measured

macOS 26.6 VM (paravirtual Metal GPU), our screenshot app (a menu-bar app with a main window that shows a grid of 24 thumbnails), Rune dev dacf5d89 with no patches. The app drops all its thumbnail Pixels 2 s after the main window hides. Malloc stack logging 8 s after the hide, regions with 0.25 MB or more resident:

owner MB regions
Pixels the app made for its thumbnails (the app freed its copies at 2 s) 13.9 24
ImageAtlas page buffers (ImagePage::allocate, ImagePage::new) 10.5 4
Rune runtime (motion, layout, text) about 3.5 6
all untagged (VM_ALLOCATE) 28.4

The same app on GPUI, same steps: 1.4 MB untagged in all. GPUI gives the thumbnails back when the app drops them.

Ask

When the app state of a hidden window changes, drop the element clones that hold Pixels. For example, build the view once without drawing it after the change, or drop the last view at hide and build it again before the next show. Then a hidden window holds no image that the app let go, and its atlas pages can go too.

Done when: an app that drops a Pixels while its window is hidden sees that memory freed without showing the window.

Related: #163 (atlas page CPU copies), #161 (hidden window drawables).


Posted via Claude

Activity

  1. Hona commented on Nov 28, 2026

    @Hona
    Member

    Fixed in #2686 (7205f2d44cc14f56c068b4777ea6ffc3cbcdcb9d).

    Design decision: Instead of rebuilding views while hidden, Rune now releases all retained Pixels / Image references and CPU ImageAtlas pages via RuntimeCore::drop_images() whenever a window, overlay, or web tab hides or rests unseen—and also when state changes (update / poll) while hidden. drop_images() clears El::pixels, El::image_menu, text pill/inline images, InputSpec::pill_image, spare nodes, image-holding memos (tracked via Built::has_pixels), and virtual list offscreen elements/pins, then marks the view dirty so the next visible frame rebuilds and re-uploads only what is still shown. Visible idle rest keeps displayed images resident, and windows with no images leave memos and dirty untouched.

    Verified locally (Windows, DX12 headless GPU + CPU tests):

    • Added regression tests in crates/rune/src/runtime/rest_tests.rs proving Weak::upgrade() drops to None immediately when the app drops its Pixels / Image handles after hidden rest, hidden update, or hidden poll (without rebuilding the view while hidden), and proving kept images rebuild cleanly on show.
    • Updated overlay::rest_tests and ran runtime::rest::tests, overlay::rest_tests, overlay::state_walk_tests::wayland_hide_drops_pixels, overlay::tests::overlay_pixels_wake_only_while_shown_and_catch_up_on_show, overlay::retire::tests::drop_hidden_images, render::upload::tests::give_back, runtime::drop_tests, runtime::hidden_wake_tests, runtime::live_only_tests, and window::state::covered_tests (all passed), plus cargo check -p rune --target wasm32-unknown-unknown.

    Not run locally: real macOS/Metal VM malloc-stack profiling, Linux X11/Wayland native windows, or live browser tabs. Please reopen if a hidden window still pins Pixels or atlas pages on macOS or elsewhere.

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