Repository navigation
Description
What happened?
I called engine.load() on a remote Blu-ray ISO (~59 GB, served over HTTP with byte-range support). Playback works, but process memory grows continuously and rapidly for the entire session: malloc in-use size climbs at roughly 30 MB/s (~6 GB after 150 s). RSS looks deceptively flat because the leaked pages are never touched again and get moved into the macOS compressor (vmCmp climbs steadily in the memprobe lines below). Left running, the process is eventually jetsammed.
Steps to reproduce
- Serve a Blu-ray ISO from any HTTP server with range-request support
engine.load(url:)on the ISO URL — the engine recognizes the BDMV and routes it throughDiscReader/HTTPDiscIOReader(the pull path viaCustomIOReaderBridge).- Let it play and watch the
[AetherEngine] memprobelines:mallocMBandvmCmpgrow linearly (~800–900 MB per 30 s).
AetherEngine version or commit SHA
5.28.0
Host app
Custom / my own integration
Platform
macOS
OS version
macOS 15.7.7
Device / chip
Mac mini m4
Playback path
Native AVPlayer
Source media (for playback bugs)
Blu-ray ISO (UDF/BDMV), ~59.11 GB. Selected title: AV1 (av01), 3840x2160, HDR10, 23.976 fps, 13 audio tracks, 13 PGS subtitle tracks.
Error codes / log lines
[AetherEngine] memprobe t=30s rss=1991MB vmInt=1629MB vmExt=240MB vmCmp=456MB vmIOS=0MB physFP=1481MB
mallocBlocks=1042068 mallocMB=2476 avioFetchedMB=0 cacheCount=20 cacheMB=304 packetsWritten=1910 audioFifo=0
abFifoKB=0 abSwrKB=0 abTotKB=0 muxBytesMB=304 muxCuts=20 srvConns=1 srvBytesMB=150 srvSfMB=122 pktAlive=3
pktTotal=44073 subCues=2 prefetch=park prefetchLead=59.8s prefetchHarvested=14434 prefetchTbFallback=0 swFrames=0
audioTracks=13 subTracks=13 subActive=true avBufAhead=5.8s avBufBehind=31.9s frameAhead=0.00s prodShift=2.69s
hostShift=2.69s seams=1
[AetherEngine] memprobe t=60s rss=1608MB vmInt=1368MB vmExt=240MB vmCmp=1203MB vmIOS=0MB physFP=1935MB
mallocBlocks=1297122 mallocMB=3442 avioFetchedMB=0 cacheCount=27 cacheMB=447 packetsWritten=2643 audioFifo=0
abFifoKB=0 abSwrKB=0 abTotKB=0 muxBytesMB=447 muxCuts=27 srvConns=1 srvBytesMB=269 srvSfMB=241 pktAlive=2
pktTotal=60998 subCues=2 prefetch=park prefetchLead=59.5s prefetchHarvested=20443 prefetchTbFallback=0 swFrames=0
audioTracks=13 subTracks=13 subActive=true avBufAhead=7.8s avBufBehind=30.2s frameAhead=0.00s prodShift=2.69s
hostShift=2.69s seams=1
[AetherEngine] memprobe t=90s rss=1605MB vmInt=1367MB vmExt=237MB vmCmp=1658MB vmIOS=0MB physFP=2422MB
mallocBlocks=1552671 mallocMB=4311 avioFetchedMB=0 cacheCount=35 cacheMB=589 packetsWritten=3349 audioFifo=0
abFifoKB=0 abSwrKB=0 abTotKB=0 muxBytesMB=589 muxCuts=35 srvConns=1 srvBytesMB=407 srvSfMB=380 pktAlive=3
pktTotal=78040 subCues=2 prefetch=park prefetchLead=59.8s prefetchHarvested=25490 prefetchTbFallback=0 swFrames=0
audioTracks=13 subTracks=13 subActive=true avBufAhead=5.8s avBufBehind=32.2s frameAhead=0.00s prodShift=2.69s
hostShift=2.69s seams=1
[AetherEngine] memprobe t=120s rss=1528MB vmInt=1357MB vmExt=171MB vmCmp=2065MB vmIOS=0MB physFP=2786MB
mallocBlocks=1817452 mallocMB=5115 avioFetchedMB=0 cacheCount=43 cacheMB=711 packetsWritten=4117 audioFifo=0
abFifoKB=0 abSwrKB=0 abTotKB=0 muxBytesMB=711 muxCuts=43 srvConns=1 srvBytesMB=552 srvSfMB=524 pktAlive=3
pktTotal=97247 subCues=2 prefetch=park prefetchLead=59.8s prefetchHarvested=31410 prefetchTbFallback=0 swFrames=0
audioTracks=13 subTracks=13 subActive=true avBufAhead=7.7s avBufBehind=30.2s frameAhead=0.00s prodShift=2.69s
hostShift=2.69s seams=1
[AetherEngine] memprobe t=150s rss=1293MB vmInt=1157MB vmExt=136MB vmCmp=2805MB vmIOS=0MB physFP=3295MB
mallocBlocks=2098578 mallocMB=6081 avioFetchedMB=0 cacheCount=50 cacheMB=867 packetsWritten=4790 audioFifo=0
abFifoKB=0 abSwrKB=0 abTotKB=0 muxBytesMB=867 muxCuts=50 srvConns=1 srvBytesMB=679 srvSfMB=651 pktAlive=3
pktTotal=111138 subCues=2 prefetch=park prefetchLead=59.8s prefetchHarvested=35786 prefetchTbFallback=0 swFrames=0
audioTracks=13 subTracks=13 subActive=true avBufAhead=5.7s avBufBehind=32.2s frameAhead=0.00s prodShift=2.69s
hostShift=2.69s seams=1
Anything else
Root cause analysis / fix suggestion
The leak is in HTTPDiscIOReader.rangeGet (Sources/AetherEngine/IO/HTTPDiscIOReader.swift). The disc path is pull-based: FFmpeg's read callback runs on the demux thread and synchronously performs each range request there (session.dataTask(with:) + semaphore wait). dataTask(with:) and the surrounding Foundation bridging produce autoreleased ObjC objects — including the task, which retains request/response buffers. The demux pump thread is a long-lived busy loop that never drains an autorelease pool, so every range fetch strands its objects for the lifetime of the session.
The arithmetic matches: three concurrent readers (main demuxer + subtitle side demuxer + 60 s forward-prefetch demuxer, each with an independent HTTPDiscIOReader fork) × ~8 MB adaptive chunks at a few requests/s ≈ 30 MB/s.
Suggested fix: wrap the body of rangeGet in autoreleasepool { ... } so each request's autoreleased objects are released as soon as the synchronous round-trip completes. This covers probeSize and fetchWithRetry too, since both go through rangeGet. Verified locally: with the wrapper, mallocMB/vmCmp stay flat during ISO playback.
Activity
docs(io): correct the AVIOReader session comments after the #243 meas…
Merge pull request #245 from superuser404notfound/fix/issue243-reader…
superuser404notfound commentedon Jul 29, 2026
Fixed in 5.28.2 (PR #245). Thanks for a report that arrived with the site, the mechanism and the fix already in it, and for reading the compressor behaviour correctly off the memprobe lines:
rssstaying flat whilevmCmpandphysFPclimb is exactly what sends this class of leak unnoticed for a while.rangeGetnow drains per request, which coversprobeSizeand every retry as suggested. Two things came out of verifying it.The local twin had the same defect.
FileIOReader.readhands back an NSData-backedDatafromFileHandle.readon that same never-draining thread, so a local disc image leaked one byte per byte played: 624 MB read in 32 KB chunks left 625 MB in use, and 0 MB with the pool.SMBIOReadercopies out of a dispatch_data-backed body there too and got the same wrapper.A per-request
URLSessionis not a fix, which matters because the engine's older comments claimed it was. Measured against a local range origin, 480 MB fetched in 8 MB requests:So the retention was never inside URLSession's task pool, as the AVIOReader leak of 5.x had been recorded. The owner is the caller thread's pool in both cases, and delegate-based delivery worked there because it releases the body on the delegate queue, where the demux thread never sees it. Those comments are corrected.
5.28.2 also adds
discFetchedMBto the 30 s memprobe. The disc pull path had no byte counter at all (avioFetchedMBcovers the AVIOReader path only), which is why this session reports every engine-tracked pool flat while three reader forks pull tens of MB/s. On a retest it gives the fetch rate directly, so the expectation ismallocMBandvmCmpflat whilediscFetchedMBkeeps climbing at roughly the media rate times the number of active readers.Leaving this open for a retest on the same ISO. If anything still grows, the memprobe lines with
discFetchedMBin them are the useful ones.fix(io): drain the reader's autorelease pool per read (superuser404no…
bitxeno commentedon Jul 29, 2026
I retested, the memory growth is gone now.
fix(io): drain the pool a host reader allocates into
fix(dv): a P8.1 on a panel without Dolby Vision keeps its dvcC
fix(test): the #243 fetch-tally test tolerates a parallel session start