Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synth.onsilence is unreliable at scale #1296

Open
mildfuzz opened this issue Dec 3, 2024 · 1 comment
Open

Synth.onsilence is unreliable at scale #1296

mildfuzz opened this issue Dec 3, 2024 · 1 comment

Comments

@mildfuzz
Copy link

mildfuzz commented Dec 3, 2024

I have managed to contrive a reproduction.

We have an arbitrary synth buffer (50). Once that is full no more will be created

After 10 seconds, the remaining buffers (that didn't get disposed of) are logged to console. We expect zero, but we usually get over 30.

This is causing memory leaks in my real world app as synths are not cleaning up after themselves

https://codesandbox.io/p/sandbox/synth-onsilence-forked-xygrhy?workspaceId=6877f6b3-5e2a-423a-a4c1-5b098cab00e5

@mildfuzz
Copy link
Author

mildfuzz commented Dec 3, 2024

for now, I am able to work around it by deducing note time, adding a slight buffer, and using setTimeout

synth.triggerAttackRelease(this.sounds.nextNote, '16n')

    const totalSynthTimeMS = (Tone.Time('16n').toSeconds() + 0.1) * 1000

    setTimeout(
      ((s: Tone.FMSynth) => {
        this.synths.delete(synth)
        s.dispose()
      }).bind(this, synth),
      totalSynthTimeMS,
    )

But this might be harder to manage when I have lots of instrument types

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

No branches or pull requests

1 participant