onEnded listeners are never removed, so every AudioBufferSourceNode stays alive (and its buffer counts as Hermes external memory) until the app runs out of memory
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 57/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- android, cpp, ios, javascript, react-native
調査の方向性
Start by tracing AudioScheduledSourceNode's onEnded setter and the native AudioEventEmitter subscription it creates; the issue identifies both as the leak path. Check how subscriptions are stored and removed when the handler changes, is set to null, or ended fires. Done means replaced and cleared handlers release their subscriptions so finished nodes can be collected; the reproduction's Hermes external memory should stop growing.
索引モデルが issue の本文から書いたものです。
説明
Description
Setting node.onEnded = callback on an AudioBufferSourceNode (any AudioScheduledSourceNode) registers a listener with the native AudioEventEmitter (addAudioEventListener('ended', …)), but the returned subscription is never removed:
- not when the
endedevent fires, - not when
onEndedis set tonull(the setter only sets the node's native listener id to'0'; the subscription stays in the emitter).
The emitter keeps the jsi::Function, the closure keeps the JS node, and the JS node keeps the native node. Each AudioBufferSourceNodeHostObject also calls setExternalMemoryPressure with its buffer's full size, so Hermes' external memory grows with every node that ever had onEnded set, and it never comes back down.
Impact: an app that schedules overlapping buffer segments (a seamless ambient loop: a new AudioBufferSourceNode every 16 s, each with onEnded to disconnect it) climbs steadily: Hermes js_externalBytes reached 2.9 GB after 24 minutes (Pixel 10 Pro XL) and 4.0 GB within minutes on a Pixel 8a, after which the OS killed the app with no JS error. iOS crashed the same way (Hermes out of memory at 2.2 GB).
Expected: the subscription is removed when onEnded is replaced or set to null (and ideally after ended fires for a node that can't start again), so finished nodes can be garbage-collected.
Suggested fix: keep the AudioEventSubscription returned by addAudioEventListener on the node and call remove() on it in the onEnded setter before registering a new one or when the value is null; consider removing it automatically after the ended event of a buffer source.
Workaround we use: no onEnded on segment nodes; a 1-second timer disconnects each one a second after its scheduled end.
Steps to reproduce
- In a development build (Hermes), run:
const ctx = new AudioContext();
const buf = ctx.createBuffer(2, ctx.sampleRate * 16, ctx.sampleRate);
setInterval(() => {
const src = ctx.createBufferSource();
src.buffer = buf;
src.connect(ctx.destination);
src.onEnded = () => { src.disconnect(); src.onEnded = null; };
src.start(); src.stop(ctx.currentTime + 1);
}, 1000);
- Log
HermesInternal.getInstrumentedStats().js_externalBytesevery few seconds: it grows ~12 MB per second and is never collected. - Remove the
src.onEnded = …line and run again:js_externalBytesstays flat (the nodes are collected).
Snack or a link to a repository
https://github.com/jessenicholsfromsanfrancisco/rnaa-onended-leak-repro
React Native Audio API version
0.13.6
React Native version
0.88.1
Platforms
Android, iOS
JavaScript runtime
Hermes
Workflow
Expo Dev Client
Architecture
Fabric (New Architecture)
Build type
Release app & dev bundle
Device
Real device
Device model
iPhone 15
Acknowledgements
Yes
- 主要言語
- C++
- スター
- 856
- フォーク
- 100
- 平均マージ
- 2日 1時間
- マージ済み PR(30日)
- 34
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
software-mansion/react-native-audio-api のほかの issue
-
Android: audio focus listener posts to a dead looper after JS reload, interruptions (calls) are missed対応中かも @JaydeepAgravat が 1 日前に担当しました。 オープンandroid bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
software-mansion/react-native-audio-api#1358 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
android bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
software-mansion/react-native-audio-api#1273 · コメント 5 件 ·
メンテナーはふだん 1 日以内に返信
-
bug ios
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
software-mansion/react-native-audio-api#1238 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
software-mansion/react-native-audio-api#1416 ·
メンテナーはふだん 1 日以内に返信
-
feature-request ios
難易度 5/5 1週間以上 初心者へのやさしさ 45/100
software-mansion/react-native-audio-api#1398 ·
メンテナーはふだん 1 日以内に返信
software-mansion/react-native-audio-api の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
ROCm/AMDMIGraphX#5490 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
arvidn/libtorrent#9126 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Sunrisepeak/mcpp-language-server#80 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
xiaoyifang/goldendict-ng#3148 ·
メンテナーはふだん 1 日以内に返信