Re: Lifetime of new Audio()

On Sun, Jan 30, 2011 at 5:52 PM, Adrian Bateman <adrianba@microsoft.com> wrote:
> I have a question about an audio element created using the constructor. Consider the following function:
>
> function playAudio() {
>  var a = new Audio("http://www.example.com/music");
>  a.play();
> }
>
> Ignoring for now the timing issue of how quickly the play() actually has enough content to start playing, after the function returns there is no reference to the Audio object. Is the fact that the object is playing enough to pin it in memory? Otherwise the GC could collect the object and stop the playing. I scanned the media section of the spec but couldn't see where it defines this behaviour one way or the other.
>
> Any thoughts?

In general, I think GC should never be noticeable. Any time the author
or the user can notice that GC happened, there is a big in the
implementation or the spec.

So in this case I think yes, playing should ensure that the object
doesn't get GCed. Or rather, GC should not stop the sound from
playing. Technically you could push the sound file to the sound
subsystem and then destroy the element as that would be
indistinguishable for everyone. At least as long as no event handlers
are attached to the element.

/ Jonas

Received on Monday, 31 January 2011 03:44:43 UTC