Skip to content

fix(desktop): release leaked NSGlassEffectView on re-apply#1912

Merged
richiemcilroy merged 2 commits into
CapSoftware:mainfrom
ManthanNimodiya:fix/liquid-glass-view-leak
Jun 12, 2026
Merged

fix(desktop): release leaked NSGlassEffectView on re-apply#1912
richiemcilroy merged 2 commits into
CapSoftware:mainfrom
ManthanNimodiya:fix/liquid-glass-view-leak

Conversation

@ManthanNimodiya

@ManthanNimodiya ManthanNimodiya commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Summary

apply_liquid_glass_background does alloc + initWithFrame on an NSGlassEffectView (a +1 retain from alloc) and adds it as a subview.
remove_liquid_glass_subviews only called removeFromSuperview, which drops the superview's retain but never balances the original alloc, so every re-apply (e.g. each window-chrome route navigation that triggers createEffect) permanently leaks one GPU/IOSurface-backed NSGlassEffectView at refcount 1.

This adds the matching release after removeFromSuperview to balance
ownership.

Test plan

  • Verified with a standalone harness mirroring the exact alloc → addSubview → removeFromSuperview → release sequence on macOS 26 (NSGlassEffectView):
  • Without the fix: dealloc is never called across repeatedre-applies (leak reproduced).
  • With the fix: every replaced glass view is deallocated exactly once, with no double-free.
  • cargo check passes for cap-desktop.

Greptile Summary

Fixes a memory leak in the macOS Liquid Glass background feature where every call to apply_liquid_glass_background permanently leaked one GPU/IOSurface-backed NSGlassEffectView. The root cause was that alloc + initWithFrame gave the Rust caller a +1 ownership retain, but remove_liquid_glass_subviews only called removeFromSuperview (which drops the superview's retain), leaving the alloc retain permanently unbalanced.

  • Adds a single msg_send![view, release] immediately after removeFromSuperview in remove_liquid_glass_subviews, consistent with the identical pattern already present in the early-return path of apply_liquid_glass_background (line 228).
  • The subviews NSArray snapshot, which is returned autoreleased and retains each element, keeps each view alive through the release call, so there is no use-after-free risk during the iteration.
  • The reverse-order loop is already correct for removal safety, and the continue after release prevents any further use of the pointer.

Confidence Score: 5/5

The change is a single-line addition that correctly balances a known alloc/release pair; no existing behavior is altered beyond reclaiming the leaked memory.

The fix mirrors the identical release pattern used in the early-bailout path of apply_liquid_glass_background (line 228), confirming this is the right idiom for this codebase. The NSArray snapshot retains each view element throughout the loop, so there is no use-after-free exposure, and the continue ensures the pointer is never touched after the release. No other call site needs updating.

No files require special attention.

Important Files Changed

Filename Overview
apps/desktop/src-tauri/src/platform/macos/mod.rs Adds a balancing release after removeFromSuperview in remove_liquid_glass_subviews to fix a memory leak of alloc-owned NSGlassEffectView objects on every re-apply.

Reviews (1): Last reviewed commit: "fix(desktop): release leaked NSGlassEffe..." | Re-trigger Greptile

@superagent-security

Copy link
Copy Markdown

Superagent didn't find any vulnerabilities or security issues in this PR.

@richiemcilroy richiemcilroy merged commit a0424f2 into CapSoftware:main Jun 12, 2026
13 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants