Skip to content
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

Merged
merged 1 commit into from
Sep 19, 2022

Conversation

sschmidTU
Copy link

@sschmidTU sschmidTU commented Sep 6, 2022

Playing many repeated sounds over time, e.g. a music sheet, causes memory to leak and build up constantly, the more sounds are played.
image

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.

image

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.

@danigb
Copy link
Owner

danigb commented Sep 19, 2022

Hi @sschmidTU

Thanks for the PR. As you can see, this library is mostly abandoned. I don't remember almost anything about the internals (and I'm quite sure I'd do things very differently), so I'll merge your PR without reviewing very deeply.

Feel free to create more PRs if you find anything else. Also, I'd more than happy if someone (you or @Charlottecuc ? 😇 ) takes care of library :-)

@danigb danigb merged commit 5bd90d2 into danigb:master Sep 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants