Skip to content

Wayland: a hidden overlay keeps its last images in memory, and release_gpu_when_hidden does nothing there #142

Closed

Description

@godismyjudge95

What happens

On Wayland (layer-shell or the XWayland fallback), hiding an overlay drops its surface but keeps its renderer, its image atlas pages and its last committed view. An image the overlay showed stays in memory until the overlay shows again, even after the app has dropped its own Pixels. For a screenshot overlay that is one or two copies of a full-screen frame (23.8 MB each at 3024x1964 RGBA).

Where

At dev d03349e2:

  • overlay.rs#L713: on hide, Backing::Layer and Backing::Xwayland do self.live.take(). self.renderer, self.gpu and the runtime's scene stay.
  • overlay.rs#L888-L889: park, which release_gpu_when_hidden calls, returns at once unless the backing is Backing::Window. On Wayland live is already None there, so the renderer and device are never parked. This is from reading the code; we did not set release_gpu_when_hidden ourselves.
  • pixels.rs#L295-L316: ImageAtlas::end_frame frees a page that showed nothing only at the end of a drawn frame. A hidden overlay draws no frame, so the page from its last shown frame keeps its data and its texture.

Measured

Our app: a region overlay that shows a frozen 3024x1964 frame, then hides. Ubuntu 26.04, GNOME 50 Wayland (XWayland overlay), VM with no GPU (lavapipe), 5 alternating runs per side, process PSS, median. Two app-side changes, each measured as its own before/after batch:

app change metric before after
empty the shared Pixels on end (frame.set(0, 0, Vec::new())), after the app already dropped its handle after 10 captures 335.2 MB 315.2 MB
same idle, hidden 332.3 MB 312.3 MB
draw one more frame without the image, then hide after 10 captures 310.9 MB 289.2 MB
same idle, hidden 308.0 MB 286.3 MB

Each row has p = 0.008 (rank-sum). The first change frees the frame that the overlay's last committed view still referenced. The second lets end_frame free the atlas page. The extra frame delays the hide by up to 150 ms and needs extra state in the app.

Repro

  1. An overlay whose view shows El::pixels(&p), with p set to a 3000x2000 RGBA image.
  2. Show it, let it draw, hide it. Then drop the app's p.
  3. Check the process RSS, or in a headless test the overlay renderer's ImageAtlas::pages. The image's bytes are still held.

The numbers above are from our app. We have not run this minimal repro.

Expected

When a Wayland overlay hides (its surface is gone anyway), Rune drops what only that surface's frames needed: the atlas pages and textures for images, and the references to Pixels in the last committed view. Or release_gpu_when_hidden parks the renderer on Wayland too, as on X11. The next show uploads again.

Done when: on Wayland, an overlay that showed a large Pixels and was hidden holds no copy of those pixels (CPU or GPU) once the app drops its Pixels, with no extra frame drawn by the app, and release_gpu_when_hidden parks the renderer on Wayland.


Posted via Claude

Activity

  1. godismyjudge95 commented on Nov 6, 2026

    @godismyjudge95
    Author

    Related context:


    Posted via Claude

  2. purian23 commented on Nov 12, 2026

    @purian23

    The release_gpu_when_hidden half has a small fix. Hiding a layer overlay destroys its surface, so park() finds no surface and returns early, and the renderer and device hold are kept. park() should release those two even when the surface is already gone. In our case a hidden 1,000-row launcher went from 55.4 to 47.2 MB of GPU memory.

    A second gap on the same path: a shared device isn't polled on hide, so its finished frames aren't retired until some other surface draws. Polling it in park() fixes it.

  3. Hona commented on Nov 23, 2026

    @Hona
    Member

    When an overlay hid on Wayland, its surface was destroyed first, so the GPU release returned early and the renderer, image pages and the last frame's Pixels stayed alive. Fixed on dev in #1465 (50c194f): a Wayland hide now drops those images, and release_gpu_when_hidden parks the renderer and device there too.

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