Giter VIP home page Giter VIP logo

Comments (3)

karlt avatar karlt commented on August 16, 2024

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 MessagePorts 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 MessagePorts 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.

daxpedda avatar daxpedda commented on August 16, 2024

Would similar issues apply to other Worklet types or is this problem specific to AudioWorklet because it allows communication through MessagePort?

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, but AudioWorkletGlobalScope 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.

hoch avatar hoch commented on August 16, 2024

Thanks both for the discussion! FWIW, I agree with @karlt's response.

from web-audio-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.