[whatwg] SharedWorkers and "document discarded"

Drew Wilson atwilson at google.com
Wed Feb 9 14:30:30 PST 2011


Hi all,

Jonas brought up an interesting point regarding SharedWorkers in an
unrelated thread that I wanted to clarify here.

His contention is that the current SharedWorker spec specifies that the
lifecycle of a SharedWorker is currently tied to the GC behavior of the
underlying VM - specifically, that a SharedWorker is shutdown after its last
parent document has been GC'd.

The relevant spec language is (from
http://www.whatwg.org/specs/web-workers/current-work/#the-worker's-lifetime
):

Whenever a Document d is added to the worker's Documents, the user agent
must, for each worker in the list of the worker's
workers<http://www.whatwg.org/specs/web-workers/current-work/#the-worker's-workers>
whose
list of the worker's
Documents<http://www.whatwg.org/specs/web-workers/current-work/#the-worker's-documents>
does
not contain d, add dto q's WorkerGlobalScope owner's list of the worker's
Documents<http://www.whatwg.org/specs/web-workers/current-work/#add-a-document-to-the-worker's-documents>
.

Whenever a Document object is discarded, it must be removed from the list
of the worker's
Documents<http://www.whatwg.org/specs/web-workers/current-work/#the-worker's-documents>
of
each worker whose list contains that Document.
So I'm not an expert on Document lifecycles, so I don't entirely understand
under which circumstances the spec requires that a Document object be
"discarded". For example, if I have a top level window with a child iframe,
and that child iframe creates a SharedWorker, then reloads itself or
navigates, could that cause the original document to be discarded/suspended,
or does this depend on GC (whether script in the top level window maintains
a reference to the document javascript object)?

My understanding from previous discussions was that the only thing impacting
whether a document is discarded is whether the UA decided to keep it
suspended in the history cache - can javascript-level references also
prevent a document from being discarded?

-atw


More information about the whatwg mailing list