Re: PSA: Don't write out multiple Add/RemoveObserver calls manually, iterate over an array instead

2014-02-18 Thread Chris Peterson

On 2/17/14, 11:25 AM, Kyle Huey wrote:

If you are observing several topics it's easy to forget to add a
Remove call when adding new observer topic.  If you instead write an
array of topics and iterate over that it's impossible to screw up
(e.g.https://hg.mozilla.org/mozilla-central/rev/3a8fe7c942e3).


To make leaking observers even impossibler, why not add addObservers() 
and removeObservers() helper functions to nsIObserverService?



chris
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Re: PSA: Don't write out multiple Add/RemoveObserver calls manually, iterate over an array instead

2014-02-18 Thread Ben Kelly

On 2/17/2014 2:25 PM, Kyle Huey wrote:

If you are observing several topics it's easy to forget to add a
Remove call when adding new observer topic.  If you instead write an
array of topics and iterate over that it's impossible to screw up
(e.g. https://hg.mozilla.org/mozilla-central/rev/3a8fe7c942e3).  We've
seen a couple of leaks caused by forgetting to remove all observers
(e.g. https://bugzilla.mozilla.org/show_bug.cgi?id=968536#c0).


Would it be worth adding an AddObservers()/RemoveObservers() API that 
takes an array directly?  That might encourage this pattern.


Just a thought.

Ben
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform