On 2014-11-24 8:49 AM, Tim Chien wrote:
Hi,

I didn't find any documentation so that I figured I should ask. So in
bug 1103574 I changed the Keyboard app so that it would start using
Web Audio API instead of multiple <audio> to play that clicker sound,
but doing so I would hold an AudioContext instance (and two
AudioBuffer instances) whenever the clicker sound is enabled (even
when keyboard is not visible). Does that poses any side effect on B2G
or in general?

Each AudioContext object is kept alive for as long as the corresponding Window object is alive even if you release all of the references to it from JS, so this shouldn't change anything.

Also, there are posts online saying AudioNodes are only GC'd when they
are disconnect()'d, I doubt that is the case (since the node is not
reachable from the context) but it seems to me there are no obvious
way to confirm that. Should I always disconnect the node after calling
start(0)? What's the definite way to find out questions like this?

What you have read is almost correct, but the exact criteria is more complicated than that. Firstly please note that the API doesn't provide any ways of accessing a node after you lose your last reference to it. The high-level criteria is like this: each node will be kept alive for as long as it has outstanding references from JS or it is able to play back audio. That means that the node will not be GCed if it has for example another node connected to it that the script has access to, because the script can potentially cause playback on the input node. For more gory details, please see <http://webaudio.github.io/web-audio-api/#lifetime-1>. But to answer your specific question above, if you have a source node (that doesn't have any inputs by definition) and call start(0) on it and lose your reference to it, the node will stay alive as long as the playback is ongoing and will be deallocated shortly afterwards. (And if you for example set up the node to loop indefinitely, the node will never be deallocated since it can always cause playback.)

Also note that in the Gecko implementation, the lifetime of the nodes is almost always controlled by the cycle collector so the time at which the nodes are deallocated is not deterministic. That being said, you can see the nodes disappear in the Web Audio devtools panel.

Cheers,
Ehsan
_______________________________________________
dev-b2g mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-b2g

Reply via email to