-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Description
You can see from the DevTools memory browser that this example has a leak. I encountered this in the app I am working on.
Reproduction:
- Single Tone.Synth with basic ADSR envelope
- Tone.Loop calling synth.triggerAttackRelease(440, '32n', time) at 8Hz
- Chrome heap snapshot after 60 seconds: 1,738+ AudioParam objects with methods {linearRampToValueAtTime, cancelScheduledValues, setValueCurveAtTime} retained in memory
Workaround I'm using (more or less)
// Setup (once)
const osc = new Tone.Oscillator(440, 'sine').start();
const gain = new Tone.Gain(0);
osc.connect(gain).toDestination();
// Loop (8Hz)
new Tone.Loop((time) => {
const attack = 0.005;
const duration = Tone.Time('32n').toSeconds();
const release = 0.005;
// Cancel automation at pulse start only
gain.gain.cancelScheduledValues(time);
// Manual envelope with smooth ramps
gain.gain.setValueAtTime(0, time);
gain.gain.linearRampToValueAtTime(1, time + attack);
gain.gain.setValueAtTime(1, time + attack + (duration - attack - release));
gain.gain.linearRampToValueAtTime(0, time + duration);
}, '16n');
Metadata
Metadata
Assignees
Labels
No labels