Repository navigation
fix(ios): drain an autorelease pool per frame in compressWithBitrate - #15
Merged
thangdevalone merged 1 commit intoNov 19, 2026
Conversation
The video loop in compressWithBitrate can append hundreds of frames in one requestMediaDataWhenReady callback when the encoder keeps up (e.g. 4K60 scaled to 720p). Without a per-iteration pool every decoded source frame stayed alive until the callback returned, so 4K60 sources grew to several GB and iOS killed the app or reset media services (AVFoundationErrorDomain -11819). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What
On iOS,
compressWithBitrate's video loop now wraps each frame inautoreleasepool. The loop body is unchanged apart fromreturn/continuebecoming the closure'sBoolresult.Why
requestMediaDataWhenReadycan append hundreds of frames in a single callback when the encoder keeps up, for example a 4K 60 fps source scaled down to 720p. Without a per-frame pool, every decoded source frame (about 12 MB at 4K) stayed alive until the callback returned. On an iPhone 17 Pro Max, compressing a 10 s range of a 4K60 HDR clip pushed the app to 2.0–2.7 GB. iOS then either killed the app (out of memory) or failed the export withAVFoundationErrorDomain -11819("Cannot Complete Action", media services reset, underlyingOSStatus -16155). 4K30 and 1080p clips stayed under the limit, which is why only high-frame-rate 4K sources showed it.Testing
compressWithBitratewas copied unchanged into a macOS command-line harness and run on synthetic clips: bitrate 4.2 Mbps,maxWidth1280, audio muted. On macOS the hardware decoder runs inVTDecoderXPCService, so the numbers below are that process's peakphys_footprint.Output sizes and encode times are unchanged; the path without resizing (
maxWidth0) also works.yarn typecheckpasses andswiftc -parseis clean. This ships in Relive as a patch on 2.4.2.🤖 Generated with Claude Code