W3C home > Mailing lists > Public > public-html@w3.org > January 2011

Re: Lifetime of new Audio()

From: Jonas Sicking <jonas@sicking.cc>
Date: Sun, 30 Jan 2011 19:43:48 -0800
Message-ID: <AANLkTik2==M3SN-+Dco7xjuB4E52U-Nd6tjgCDXJ+L3J@mail.gmail.com>
To: Adrian Bateman <adrianba@microsoft.com>
Cc: "HTML WG (public-html@w3.org)" <public-html@w3.org>
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

This archive was generated by hypermail 2.4.0 : Saturday, 9 October 2021 18:45:30 UTC