Skip to content

fix(macos): release leaked NSScreen and display UUID references - #1367

Open
Tunglies wants to merge 2 commits into
tauri-apps:devfrom
Tunglies:fix/macos-monitor-ownership
Open

Tunglies wants to merge 2 commits into
tauri-apps:devfrom
Tunglies:fix/macos-monitor-ownership

Conversation

@Tunglies

@Tunglies Tunglies commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Fixes leaked references in macOS monitor queries:

  • Restore the historical borrowed ns_screen() contract with Retained::autorelease_ptr. The pointer requires an active autorelease pool and remains valid until it drains.
  • Release display UUID references through RAII, following Apple’s Core Foundation ownership rules. Eq/Ord/Hash now use UUID values, with display-ID fallback on failure.
  • Match current screens by display ID, borrow array candidates, and retain only the match. UUID-based monitor identity remains unchanged.

This issue was observed in a real application after five days of continuous operation and detected using leaks <PID>.

Verified locally with ownership regression tests and native macOS monitor queries.

@Tunglies
Tunglies force-pushed the fix/macos-monitor-ownership branch from d20a2f8 to 72ac07b Compare October 8, 2026 00:41
@Tunglies
Tunglies marked this pull request as ready for review October 8, 2026 00:48
@Tunglies
Tunglies requested a review from a team as a code owner October 8, 2026 00:48
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Package Changes Through 72ac07b

There are 1 changes which include tao with patch

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
tao 0.37.1 0.37.2

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

@Tunglies

Copy link
Copy Markdown
Contributor Author

Some leaks output I can sharing. NSScreen does leak small bytes.

> leaks 24361
Process 24361 is not debuggable. Due to security restrictions, leaks can only show or save contents of readonly memory of restricted processes.

Process:         clash-verge [24361]
Path:            /Applications/Clash Verge.app/Contents/MacOS/clash-verge
Load Address:    0x1028ec000
Identifier:      io.github.clash-verge-rev.clash-verge-rev
Version:         2.5.7 (2.5.7)
Code Type:       ARM64
Platform:        macOS
Parent Process:  launchd [1]
Target Type:     live task

Date/Time:       2026-10-11 17:05:33.254 +0800
Launch Time:     2026-10-03 06:46:57.194 +0800
OS Version:      macOS 27.2 (26B5086k)
Report Version:  7
Analysis Tool:   /usr/bin/leaks

Physical footprint:         150.1M
Physical footprint (peak):  166.8M
Idle exit:                  untracked
----

leaks Report Version: 4.0
Process 24361: 163236 nodes malloced for 154595 KB
Process 24361: 42 leaks for 4960 total leaked bytes.

    42 (4.84K) << TOTAL >>

      8 (1.16K) ROOT LEAK: <NSScreen 0x7c03778600> [384]
         5 (720 bytes) _state + 320 --> <ScreenLocalization 0x7c0189a030> [80]
            1 (384 bytes) __strong _displaySet.displays --> <Swift._ContiguousArrayStorage<AppKit.ScreenDisplay> 0x7c024dae80> [384]
            3 (256 bytes) __strong _nameCache._variant --> <Swift._DictionaryStorage<Swift.Int32, Swift.String> 0x7c03d5de00> [160]
               1 (64 bytes) <Swift.StringStorage 0x7bff836e40> [64]
               1 (32 bytes) <CFString 0x7c040513e0> [32]
         1 (48 bytes) _state + 184 --> <NSColorSpace 0x7c02752130> [48]
         1 (32 bytes) _state + 112 --> <NSUUID 0x7c04036700> [32]

      6 (1008 bytes) ROOT LEAK: <NSScreen 0x7c03e68480> [384]
         2 (464 bytes) _state + 320 --> <ScreenLocalization 0x7c01898c30> [80]
            1 (384 bytes) __strong _displaySet.displays --> <Swift._ContiguousArrayStorage<AppKit.ScreenDisplay> 0x7c024dab80> [384]
         1 (80 bytes) _state + 176 --> <Swift.StringStorage 0x7c01c106e0> [80]
         1 (48 bytes) _state + 184 --> <NSColorSpace 0x7c01c04d50> [48]
         1 (32 bytes) _state + 112 --> <NSUUID 0x7c03406ba0> [32]

      4 (880 bytes) ROOT LEAK: <NSScreen 0x7c03174780> [384]
         2 (464 bytes) _state + 320 --> <ScreenLocalization 0x7c02db8370> [80]
            1 (384 bytes) __strong _displaySet.displays --> <Swift._ContiguousArrayStorage<AppKit.ScreenDisplay> 0x7c024d8000> [384]
         1 (32 bytes) _state + 112 --> <NSUUID 0x7c034056c0> [32]

      4 (544 bytes) ROOT LEAK: <NSScreen 0x7c0377aa00> [384]
         1 (80 bytes) _state + 176 --> <Swift.StringStorage 0x7c025fba20> [80]
         1 (48 bytes) _state + 184 --> <NSColorSpace 0x7c027528b0> [48]
         1 (32 bytes) _state + 112 --> <NSUUID 0x7c03147380> [32]

      3 (496 bytes) ROOT LEAK: <NSScreen 0x7c03174900> [384]
         1 (80 bytes) _state + 176 --> <Swift.StringStorage 0x7c02c60f50> [80]
         1 (32 bytes) _state + 112 --> <NSUUID 0x7c034061a0> [32]

      3 (464 bytes) ROOT LEAK: <NSScreen 0x7c03e69380> [384]
         1 (48 bytes) _state + 184 --> <NSColorSpace 0x7c01c05740> [48]
         1 (32 bytes) _state + 112 --> <NSUUID 0x7c03405e60> [32]

      2 (48 bytes) ROOT LEAK: <assetURLSchemeHandler_104d299a8 0x7c037fc320> [32]
         1 (16 bytes) webview_id --> <assetURLSchemeHandler_104d299a8.webview_id (char[]) 0x7c02ce36c0> [16]

      2 (48 bytes) ROOT LEAK: <assetURLSchemeHandler_104d299a8 0x7c037fe2c0> [32]
         1 (16 bytes) webview_id --> <assetURLSchemeHandler_104d299a8.webview_id (char[]) 0x7c02ce2280> [16]

      2 (48 bytes) ROOT LEAK: <ipcURLSchemeHandler_104d299a8 0x7c037fdb00> [32]
         1 (16 bytes) webview_id --> <ipcURLSchemeHandler_104d299a8.webview_id (char[]) 0x7c02ce3500> [16]

      2 (48 bytes) ROOT LEAK: <ipcURLSchemeHandler_104d299a8 0x7c037fed80> [32]
         1 (16 bytes) webview_id --> <ipcURLSchemeHandler_104d299a8.webview_id (char[]) 0x7c02ce21f0> [16]

      2 (48 bytes) ROOT LEAK: <tauriURLSchemeHandler_104d299a8 0x7c037fdf40> [32]
         1 (16 bytes) webview_id --> <tauriURLSchemeHandler_104d299a8.webview_id (char[]) 0x7c02ce34f0> [16]

      2 (48 bytes) ROOT LEAK: <tauriURLSchemeHandler_104d299a8 0x7c037ffe20> [32]
         1 (16 bytes) webview_id --> <tauriURLSchemeHandler_104d299a8.webview_id (char[]) 0x7c02ce2060> [16]

      1 (48 bytes) ROOT LEAK: <TaoWindowDelegate 0x7c01922a00> [48]
      1 (48 bytes) ROOT LEAK: <TaoWindowDelegate 0x7c025e4690> [48]

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants