Repository navigation
fix: give back the thread ports a CPU sample is handed - #25
Merged
Merged
Conversation
task_threads returns a port for every thread along with the list, and only the list was released. Each port kept outlived its thread as a dead name, so an observed Performance panel, sampling once a second, left one behind in the app for every thread it ever ran.
heoblitz
approved these changes
Oct 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
task_threadsreturns a send right for every thread along with the list, and the CPU sampler inNectoProcessMetricsreleased only the list (vm_deallocate). Each port it kept outlives its thread as a dead name, so while the Performance panel is observing — one sample a second — the app it runs in accumulates one Mach port name for every thread it ever ran. Each port is nowmach_port_deallocated before the list is freed.Changelog
Fix the Performance plugin leaking a Mach port per sampled thread in the connected app.
Test Plan
swift test: 161 tests in 11 suites passed. The new testreleasesThreadPortsparks a short-lived thread, takes aperformance.snapshot, ends the thread, 300 times over, and comparesmach_port_namescounts: onmainit leaks 301 names; with the fix the delta stays under the 100 allowed for noise.