Comments (3)
The close()
method will not automatically release all AudioContext-created objects.
A close()
is also available on the MessagePort
and useful for releasing unreferenced resources, but script can still be triggered on the worklet thread through BaseAudioContext.audioWorklet.addModule().
Making AudioContext.close()
also close MessagePort
s could be a breaking change for any clients that, for example, might collect statistics after AudioContext.close()
. If Chrome has always done this, however, then perhaps that might not be a problem. I wonder what Chrome does to the MessagePort
s and what it does when addModule()
is called. I think I'd prefer something explicit over having messages queue but never run because the event loop stops processing them.
The worklet's lifetime is explicitly terminated only when "destroying the Document
". Worklet
has some provision for user agents choosing to terminate, but AudioWorkletGlobalScope
forbids: AudioWorkletGlobalScopes must not be terminated arbitrarily by the user agent. Worklets may of course be garbage collected if content scripts no longer have access or cannot be triggered.
If the AudioWorkletGlobalScope
were terminated, addModule
would create another. This would have no references to the previous Wasm module, unless the previously added modules somehow can obtain a reference again.
I'm not familiar enough with Wasm to fully understand the requirements and when this becomes an issue. Would similar issues apply to other Worklet
types or is this problem specific to AudioWorklet
because it allows communication through MessagePort
?
I'm not clear how Worker.terminate()
would be useful for this purpose, given that it runs in parallel and I don't see any notification of completion. I'm not familiar with the history or purpose of this method.
from web-audio-api.
Would similar issues apply to other
Worklet
types or is this problem specific toAudioWorklet
because it allows communication throughMessagePort
?
I'm not familiar enough with other worklet types, but I think it would indeed apply to any worklet type.
I'm not clear how
Worker.terminate()
would be useful for this purpose, given that it runs in parallel and I don't see any notification of completion. I'm not familiar with the history or purpose of this method.
Indeed Worker.terminate()
is not immediate and there is no notification of completion AFAIK. But workers can be prevented from running anything by just blocking indefinitely with Atomics.wait()
, which can't be done with worklets as they don't support blocking.
The worklet's lifetime is explicitly terminated only when "destroying the
Document
".Worklet
has some provision for user agents choosing to terminate, butAudioWorkletGlobalScope
forbids: AudioWorkletGlobalScopes must not be terminated arbitrarily by the user agent.
I think this resolves the clarification issue! Thank you for finding it for me.
Currently audio worklets are not garbage collected in any browser (Chrome, Firefox, Safari) when a sufficiently complex Wasm module is instantiated in them, even after dropping all references to JS values. I assume it is difficult to determine if the Wasm module could execute any code (e.g. Atomics.waitAsync()
could be used to wake up and run code at any time, or a FinalizationRegistry
could be used to call into the module when something is garbage collected).
I confirmed in Chrome and Firefox that without a Wasm module audio worklets are successfully garbage collected and it can be detected by using FinalizationRegistry
.
In conclusion the closed
state can't be used to solve this problem.
from web-audio-api.
Thanks both for the discussion! FWIW, I agree with @karlt's response.
from web-audio-api.
Related Issues (20)
- Lift autoplay restriction on a muted AudioContext HOT 7
- no ignore background noise HOT 1
- Confused by "Mono-to-stereo processing is used when all connections to the input are mono" HOT 1
- Average AudioContext.outputLatency HOT 6
- PreservePitch in web Audio API HOT 2
- Should copyToChannel accept a shared Float32Array? HOT 2
- Handling unconnected AudioWorkletNode's output HOT 11
- Device-related error reporting via AudioContext.onerror HOT 18
- Using `default` device ID for setSinkId() HOT 7
- Mono audio plays on only the left speaker if a ChannelSplitterNode is used HOT 10
- Review mute/unmute/ended and constraints on track in audioContext.createMediaStreamDestination().stream HOT 1
- AudioWorkletProcessor difficult to use i have new Idea
- add AudioNode methods function for manipulation
- Whether process() is called for an AudioWorkletNode should depend on whether the active source flag is true and whether the AudioNodes connected to inputs are actively processing HOT 4
- AudioDestinationNode numberOfOutputs=1 according to the spec, but all browsers return 0 HOT 3
- AudioWorkletProcessCallback should not be a callback type HOT 8
- Audio routed to the earpiece speaker HOT 1
- AudioContext stuck on "interrupted" in Safari HOT 1
- Can ASSN.start() start an AudioContext that would otherwise not be allowed to start? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from web-audio-api.