Re: [whatwg] BroadcastChannel memory leak

2014-06-06 Thread Ian Hickson
On Fri, 23 May 2014, Adam Barth wrote:
>
> When is it safe for a user agent to garbage collect a BroadcastChannel 
> instance?
> 
> http://www.whatwg.org/specs/web-apps/current-work/multipage/web-messaging.html#broadcasting-to-other-browsing-contexts

When there's no strong references to it from an object that itself can't 
be GC'ed. Per the spec: "While a BroadcastChannel object has an event 
listener registered for message events, there must be a strong reference 
from global object specified by the BroadcastChannel object's 
BroadcastChannel settings object to the BroadcastChannel object itself."


> Given that another document might create a new BroadcastChannel instance 
> at any time, the |message| event of the object might fire any time its 
> responsible document is fully active.  For web application that have 
> long-lived documents, the BroadcastChannel might not be eligible for 
> garbage collection for a long time.

Yeah. If the page doesn't keep an explicit reference to it, but does 
attach an event handler, it could be around forever.


> Proposal: Add a |close| method to the BroadcastChannel interface similar 
> to the |close| method on MessagePort.  The |close| method would just 
> neuter the instance of the channel and prevent it from receiving further 
> messages.

This would merely be a convenience method (you could always just remove 
the event handlers), but it seems reasonable.


On Fri, 23 May 2014, Adam Barth wrote:
> 
> That doesn't play nicely with anonymous JavaScript functions that can't 
> ever be removed as event listeners...

Well, they can remove themselves (no?). But yeah, it's not great.


On Fri, 23 May 2014, Jonas Sicking wrote:
> >
> > Proposal: Add a |close| method to the BroadcastChannel interface 
> > similar to the |close| method on MessagePort.  The |close| method 
> > would just neuter the instance of the channel and prevent it from 
> > receiving further messages.
> 
> Sounds good to me.

Done.

-- 
Ian Hickson   U+1047E)\._.,--,'``.fL
http://ln.hixie.ch/   U+263A/,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'


Re: [whatwg] BroadcastChannel memory leak

2014-05-23 Thread Jonas Sicking
On Fri, May 23, 2014 at 5:23 PM, Adam Barth  wrote:
> When is it safe for a user agent to garbage collect a BroadcastChannel 
> instance?
>
> http://www.whatwg.org/specs/web-apps/current-work/multipage/web-messaging.html#broadcasting-to-other-browsing-contexts
>
> Given that another document might create a new BroadcastChannel
> instance at any time, the |message| event of the object might fire any
> time its responsible document is fully active.  For web application
> that have long-lived documents, the BroadcastChannel might not be
> eligible for garbage collection for a long time.
>
> Proposal: Add a |close| method to the BroadcastChannel interface
> similar to the |close| method on MessagePort.  The |close| method
> would just neuter the instance of the channel and prevent it from
> receiving further messages.

Sounds good to me.

/ Jonas


Re: [whatwg] BroadcastChannel memory leak

2014-05-23 Thread Adam Barth
On Fri, May 23, 2014 at 5:54 PM, Michael Nordman  wrote:
>> When is it safe for a user agent to garbage collect a BroadcastChannel
>> instance?
>
> When there's no direct reference to the object and no onmessage handler
> attached to it. (?)

That doesn't play nicely with anonymous JavaScript functions that
can't ever be removed as event listeners...

Adam


> On Fri, May 23, 2014 at 5:23 PM, Adam Barth  wrote:
>>
>> When is it safe for a user agent to garbage collect a BroadcastChannel
>> instance?
>>
>>
>> http://www.whatwg.org/specs/web-apps/current-work/multipage/web-messaging.html#broadcasting-to-other-browsing-contexts
>>
>> Given that another document might create a new BroadcastChannel
>> instance at any time, the |message| event of the object might fire any
>> time its responsible document is fully active.  For web application
>> that have long-lived documents, the BroadcastChannel might not be
>> eligible for garbage collection for a long time.
>>
>> Proposal: Add a |close| method to the BroadcastChannel interface
>> similar to the |close| method on MessagePort.  The |close| method
>> would just neuter the instance of the channel and prevent it from
>> receiving further messages.
>>
>> Adam
>
>


Re: [whatwg] BroadcastChannel memory leak

2014-05-23 Thread Michael Nordman
> When is it safe for a user agent to garbage collect a BroadcastChannel
instance?

When there's no direct reference to the object and no onmessage handler
attached to it. (?)



On Fri, May 23, 2014 at 5:23 PM, Adam Barth  wrote:

> When is it safe for a user agent to garbage collect a BroadcastChannel
> instance?
>
>
> http://www.whatwg.org/specs/web-apps/current-work/multipage/web-messaging.html#broadcasting-to-other-browsing-contexts
>
> Given that another document might create a new BroadcastChannel
> instance at any time, the |message| event of the object might fire any
> time its responsible document is fully active.  For web application
> that have long-lived documents, the BroadcastChannel might not be
> eligible for garbage collection for a long time.
>
> Proposal: Add a |close| method to the BroadcastChannel interface
> similar to the |close| method on MessagePort.  The |close| method
> would just neuter the instance of the channel and prevent it from
> receiving further messages.
>
> Adam
>


[whatwg] BroadcastChannel memory leak

2014-05-23 Thread Adam Barth
When is it safe for a user agent to garbage collect a BroadcastChannel instance?

http://www.whatwg.org/specs/web-apps/current-work/multipage/web-messaging.html#broadcasting-to-other-browsing-contexts

Given that another document might create a new BroadcastChannel
instance at any time, the |message| event of the object might fire any
time its responsible document is fully active.  For web application
that have long-lived documents, the BroadcastChannel might not be
eligible for garbage collection for a long time.

Proposal: Add a |close| method to the BroadcastChannel interface
similar to the |close| method on MessagePort.  The |close| method
would just neuter the instance of the channel and prevent it from
receiving further messages.

Adam