You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
macOS: release_gpu_when_closed leaks one window-size surface on every hide and show #162
With App::release_gpu_when_closed, each hide destroys the window and its GPU device, and the next show makes new ones. On macOS the process footprint grows by one window-size BGRA surface on every cycle and never comes back. The growth is in "Owned physical footprint (unmapped)": memory charged to the process but mapped by nobody in it.
macOS 26.6 VM (paravirtual Metal GPU), screen 2880x1696, Rune 7ead7d63 (both files above are the same on dev except three lines that add maximize). A full-screen, borderless, hidden-by-default window with keep_running().release_gpu_when_closed(); each cycle shows it, draws a screen-size image for about 0.5 s, and hides it. footprint -v and heap 3 s after each cycle:
cycle
footprint
owned unmapped
IOSurface objects
WinitWindowDelegate objects
1
137 MB
19 MB
4
2
2
156 MB
37 MB
4
2
5
212 MB
93 MB
4
2
10
306 MB
187 MB
4
2
The growth is 18.7 MB per cycle, the size of one 2880x1696 BGRA surface (19.5 MB). The object counts stay the same, so the process holds no reference to it. Inference, not traced: the window server or the layer's render context keeps the last presented surface of the destroyed window, charged to our process.
Without the option the same 10 cycles stay at 197 MB, but the hidden window then keeps about 81 MB (see the related issue).
Repro
A window app with keep_running().release_gpu_when_closed() whose view shows a full-screen image.
Repeat 10 times: AppHandle::open, wait for a frame, AppHandle::hide, wait 3 s.
Read footprint -v <pid> after each cycle; the "Owned physical footprint (unmapped)" line grows by one surface per cycle.
The numbers are from our app; we have not run this minimal repro.
Expected
A hide and show cycle with release_gpu_when_closed returns the process to the same footprint, within a few MB, after any number of cycles.
Done when: 10 cycles on macOS end within a few MB of the first, and a test or probe that counts the cycles checks it.
Related: #80, and #161, the hidden-window memory that this option would solve if it did not leak.
On current dev, Host::release drops every reference Rune holds to the window, view, CAMetalLayer, drawables, and GPU (crates/rune/src/window/host/lifecycle.rs, crates/rune/src/window/surface/win.rs, crates/rune-gpu/src/metal/surface.rs). A 10-cycle windowless Metal probe on Apple silicon at 2880x1696 freed the layers each cycle with flat footprint.
No PR has changed this path for a real NSWindow, so we do not know whether Owned physical footprint (unmapped) still grows on current dev, on bare-metal Apple silicon, or with RUNE_GPU_BACKEND=wgpu. Because IOSurface and WinitWindowDelegate counts stayed flat, the surface appears to be held by WindowServer or the VM's paravirtual GPU.
If this still reproduces on current dev, please reopen with a repro:
Build a minimal repro with App::keep_running and App::release_gpu_when_closed showing a full-screen borderless image (--release or --profile perf).
Run 10 cycles: AppHandle::open, wait ~1 s, AppHandle::hide, wait 3 s.
Share footprint -v <pid> and heap <pid> | grep -E 'IOSurface|WinitWindowDelegate|CAMetalLayer|RawWindowMetalLayer' after cycles 1 and 10, plus a run with RUNE_GPU_BACKEND=wgpu (and bare-metal Apple silicon if available).
Activity
Hona commentedon Nov 23, 2026
On current
dev,Host::releasedrops every reference Rune holds to the window, view,CAMetalLayer, drawables, and GPU (crates/rune/src/window/host/lifecycle.rs,crates/rune/src/window/surface/win.rs,crates/rune-gpu/src/metal/surface.rs). A 10-cycle windowless Metal probe on Apple silicon at 2880x1696 freed the layers each cycle with flat footprint.No PR has changed this path for a real
NSWindow, so we do not know whetherOwned physical footprint (unmapped)still grows on currentdev, on bare-metal Apple silicon, or withRUNE_GPU_BACKEND=wgpu. BecauseIOSurfaceandWinitWindowDelegatecounts stayed flat, the surface appears to be held by WindowServer or the VM's paravirtual GPU.If this still reproduces on current
dev, please reopen with a repro:App::keep_runningandApp::release_gpu_when_closedshowing a full-screen borderless image (--releaseor--profile perf).AppHandle::open, wait ~1 s,AppHandle::hide, wait 3 s.footprint -v <pid>andheap <pid> | grep -E 'IOSurface|WinitWindowDelegate|CAMetalLayer|RawWindowMetalLayer'after cycles 1 and 10, plus a run withRUNE_GPU_BACKEND=wgpu(and bare-metal Apple silicon if available).Thanks for the detailed report and measurements.