[whatwg] Workers: What can be done in a worker after call to close()?

Jonas Sicking jonas at sicking.cc
Thu Apr 1 16:49:51 PDT 2010


On Thu, Apr 1, 2010 at 4:40 PM, Drew Wilson <atwilson at google.com> wrote:
> How does the GC-initiated close() event work in Firefox, in the case of a
> fire-and-forget worker?
> For example:
> foo.html:
> <script>
> new Worker("forget.js");
> </script>
> forget.js:
> self.setInterval(function() { ...do something...}, 1000);
> In this case, it seems incorrect to ever fire a close() event until the
> parent window leaves the bfcache. I'm guessing you must do something to
> prevent the worker object from being GC'd in the case that there's pending
> activity in the worker?

Indeed, such a worker would never be GC'd. Similarly a worker that
simply contains a infinite while(1) {} loop, or a worker that
continuously starts XHR requests at the end of the previous XHR
requests.

This isn't really related to the 'close' event though, but rather
worker lifetime.

The 'close' event would still fire at some point. Either if someone
calls terminate() from the outside, or once the user navigates away
from the page that started the worker.

/ Jonas



More information about the whatwg mailing list