Please see my in-line response.

----- Original Message -----
> From: "Fernando Jiménez Moreno" <[email protected]>
> To: "dev-b2g" <[email protected]>
> Cc: "Olli Pettay" <[email protected]>, "Kyle Huey" <[email protected]>, 
> "Gene Lian" <[email protected]>
> Sent: Tuesday, September 17, 2013 7:07:50 PM
> Subject: Message listeners added via DOMRequestHelper
> 
> Summary:
> - We need to add message listeners only when they are actually needed.
> - For "one-shot" messages associated with specific requests, we should add
> weak message listeners.

The above two make much sense to me! If the messages which an object is 
listening for are all for one-shot purpose (i.e. working for a specific 
request/promise), then there is no reason to apply strong reference to avoid 
being GC'ed since there should always be a JS reference waiting for the return. 
However, if we really want to fix all of them, we have to know the semantic of 
all the messages so that you can decide which one should be added as strong 
reference and which one should be added as weak reference. This fix probably 
needs a full understanding of all the API designs, though.

In the initiative step, I'd prefer fixing this issue from the point of view of 
*object* instead of *request/promise*. Also, as you suggested, we should use 
*strong reference* as the default, unless we're very sure an object doesn't 
need to be kept alive with the window (e.g., WebappsApplication objects), then 
we can use weak reference to register its messages. Therefore, the function 
could be something like:

initDOMRequestHelper(aWindow, aMessages, "weak"/"strong");

In the long term, we need to distinguish the types of messages to have an 
optimized way of using strong/weak references and I'd suggest turning this 
function into something like:

initDOMRequestHelper(aWindow, [{name: XXX, type: "weak"},
                               {name: XXX, type: "strong"},
                               ...]);

to force the callers to explicitly specify the type of each message.

> - For messages that should be listened during the lifetime of the window, we
> should add strong message listeners.

Indeed! Not only for the messages living with the window, we also need strong 
reference for the messages that are registered as a broadcasting way.

Gene
_______________________________________________
dev-b2g mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-b2g

Reply via email to