This repository has been archived by the owner on May 16, 2023. It is now read-only.
Fix memory leak (gainNodes piling up) by resetting nodes for repeated sounds #8
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.
Playing many repeated sounds over time, e.g. a music sheet, causes memory to leak and build up constantly, the more sounds are played.
The issue is the createNode() function, which always creates new gain nodes, which are not garbage collected.
By caching gain nodes and resetting them instead of creating new nodes, the memory leak can be avoided.
The fix here is mostly by @Charlottecuc, who didn't have the time to submit a PR (I asked for permission), with a few additions by myself to clean up and prevent stuttering in playback when similar sounds are played shortly after each other and the node is resetted too early.
I'm not expecting this PR to go through as the stutter fix is a bit inelegant, but it works, no more memory buildup during extended playback. So, for anyone looking for a solution, this is one. You can adapt it or improve it.
Unfortunately our original discussion with @Charlottecuc is in a private repository (audio player extension of OpenSheetMusicDisplay), but if you need more details, I can add them.