Skip to content

fix: a finished file source releases its decoder and frame channel - #1552

Open
jiangzhuo wants to merge 1 commit into
software-mansion:release/1.0from
jiangzhuo:fix/file-source-release-on-end
Open

jiangzhuo wants to merge 1 commit into
software-mansion:release/1.0from
jiangzhuo:fix/file-source-release-on-end

Conversation

@jiangzhuo

Copy link
Copy Markdown

Closes #1551

⚠️ Breaking changes ⚠️

  • None

Introduced changes

  • AudioFileSourceNode::disable() hands the decoder daemon and the frame channel (about 4 MB) to the context's disposer, as AudioBufferSourceNode::disable() does with its buffer. Before, both stayed until JS garbage-collected the node, and the <Audio> tag makes a new file source after every end, so each play to the end kept about 4 MB more.
  • ~SeekDecoderDaemon joins the decoding thread, so it now runs on the disposer thread instead of the audio thread. disable() still requests the stop first, and since fix: a loaded or paused file source's decoder waits instead of polling every 10 ms #1521 the stop wakes a waiting daemon, so the join is short. For a remote source the join can still wait for a network read in progress; before this change that wait happened on the JS thread when the node was collected, now it holds up the disposer thread.
  • readNextFrameChunk() returns false once the frame channel is gone. That covers a start() after the end, which renders silence as before.
  • New AudioFileSourceNodeTest: disable() releases both and the frame channel is actually freed, playing to the end releases both, and start() after the end renders silence.
  • .claude/skills/audio-nodes: one paragraph on releasing what a finished source owns in disable().

Measured with the reproduction from #1551 (Android release build, 30 plays to the end):

Native Heap TOTAL PSS
1.0.2 19.4 → 110.3 MB 60.9 → 149.5 MB
1.0.2 + this change 19.3 → 20.0 MB 66.0 → 66.1 MB

In our app (the same change on 1.0.2, a 47 s recording replayed to the end 13 times), native heap growth per replay went from about 4.1 MB to about 0.13 MB.

Not in this PR: AudioFileSourceNodeHostObject::getMemoryPressure() credits about 6 KB, while a live file source holds about 4 MB (the frame channel and the pending chunk). A source dropped without reaching the end, for example when <Audio> gets a new source mid-playback, still keeps its 4 MB until a collection. I left the credit alone because of the over-reporting notes in the host-objects skill. I can add it here or in a separate PR if you want it. A source stopped before it started also keeps them, because that path calls AudioNode::disable() directly.

Checked locally: run-tests.sh smoke (619 passed), the file source, media element and decoder daemon suites with --ubasan and with --tsan (20 repeats), and clang-format 23 and cpplint 2.0.2 on the changed files. I did not run the native example-app builds; the same change builds for Android and iOS in our app on 1.0.2.

Written with Claude Code.

Checklist

  • Linked relevant issue
  • Targets the right branch (release/X.Y only for fixes to the released version)
  • Updated relevant documentation
  • Added/Conducted relevant tests
  • Performed self-review of the code
  • Updated Web Audio API coverage
  • Added support for web
  • Updated old arch android spec file

🤖 Generated with Claude Code

disable() already stopped the decoder daemon, but the node kept the daemon and its frame
channel (64 chunks of 64 KB, about 4 MB) until JS garbage-collected the node. The <Audio>
tag replaces its file source after every end, so each play to the end left about 4 MB
behind until a collection, which the node's small memory credit does not hurry.

disable() now hands both to the context's disposer, as AudioBufferSourceNode does with its
buffer, so ~SeekDecoderDaemon's join runs on the disposer thread, not the audio thread.
readNextFrameChunk() returns false once the channel is gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Dec 4, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 392aaecb-5517-409f-994d-c9025adda74d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@mdydek

mdydek commented Dec 4, 2026

Copy link
Copy Markdown
Member

valid improvement, will port it to the #1526 on Monday, because there is already an refactor in a review

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants