Repository navigation
Conversation
Contributor
Author
|
The Android check failed before it checked out the code: Docker Hub refused to pull the |
`run` reimplements `[NSApp run]` but, unlike it, never drained an autorelease pool. So nothing autoreleased outside AppKit's own event handling was ever freed: on Metal, every frame's command buffer, and with it every texture and pass the frame drew with, since a command buffer keeps what it encodes alive. Each pass of the loop now pushes a pool and pops it at the end, as `[NSApp run]` does. Nothing autoreleased in one pass is used in the next: the frame's command buffer is made and committed within it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: multica-agent <github@multica.ai>
benface
force-pushed
the
macos-autorelease-pool
branch
from
October 18, 2026 18:00
50ec5a8 to
152d950
Compare
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.
Why
macOS's
runreimplements[NSApp run], but unlike it, it never drains an autorelease pool. So nothing autoreleased in the loop is ever freed: the eventsnextEventMatchingMask:returns, and on Metal, every frame's command buffer, render command encoders and render pass descriptor. A command buffer keeps alive what it encoded, so every texture a frame drew with stays alive too, deleted or not.#507 found the same leak during window resizes, and wraps
perform_redrawin a pool. This one puts the pool around each pass of the loop instead, as[NSApp run]does, so the events are freed as well.Change
Each pass of the loop pushes a pool and pops it at the end. Nothing autoreleased in one pass is used in the next: a frame's command buffer is made and committed within it. This is macOS only: on iOS and tvOS, UIKit's run loop already drains a pool each time round.
Measurements
On its own, this stops the slow growth of an app that deletes nothing. Deleted textures still leak on Metal, because
new_textureretains each one twice anddelete_texturereleases it once. #677 fixes that. Memory only stays flat with both.Physical footprint of a small program on macOS (Apple silicon, Metal):
A macroquad game (CHOMP) sees the same on macOS:
Verification
cargo checkpasses foraarch64-apple-darwin.🤖 Generated with Claude Code