[whatwg] WebSocket: garbage collection

On Thu, 06 May 2010 17:20:41 +0200, Simon Pieters <simonp at opera.com> wrote:

> On Tue, 20 Apr 2010 16:00:36 +0200, Simon Pieters <simonp at opera.com>  
> wrote:
>
>> [[
>> WebSocket object with an open connection must not be garbage collected  
>> if there are any event listeners registered for message events.
>> ]]
>>
>> Shouldn't it also not be garbage collected if there are listeners for  
>> open, error and close? What about when the connection is not yet  
>> established?
>
> I think the policy should be:
>
> if readyState is CONNECTING:
>    has 'open' event listener: don't collect
>    has 'message' event listener: don't collect
>    has 'error' event listener: don't collect
>    has 'close' event listener: don't collect
>
> if readyState is OPEN:
>    has 'open' event listener: OK to collect
>    has 'message' event listener: don't collect
>    has 'error' event listener: don't collect
>    has 'close' event listener: don't collect
>
> if readyState is CLOSING:
>    has 'open' event listener: OK to collect
>    has 'message' event listener: OK to collect
>    has 'error' event listener: OK to collect
>    has 'close' event listener: don't collect
>
> if readyState is CLOSED:
>    has 'open' event listener: OK to collect
>    has 'message' event listener: OK to collect
>    has 'error' event listener: OK to collect
>    has 'close' event listener: OK to collect

Make that:

  if readyState is CONNECTING:
     has 'open' event listener: don't collect
     has 'message' event listener: don't collect
     has 'error' event listener: don't collect
     has 'close' event listener: don't collect

  if readyState is OPEN or CLOSING:
     has 'open' event listener: OK to collect
     has 'message' event listener: don't collect
     has 'error' event listener: don't collect
     has 'close' event listener: don't collect

  if readyState is CLOSED:
     has 'open' event listener: OK to collect
     has 'message' event listener: OK to collect
     has 'error' event listener: OK to collect
     has 'close' event listener: OK to collect


(I didn't realize that you could get message and error events in CLOSING  
state.)

-- 
Simon Pieters
Opera Software

Received on Thursday, 20 May 2010 01:05:25 UTC