Zombie compartments in Firefox extension

Go To StackoverFlow.com

0

I'm involved into developing of Firefox extension. Our extension is complex and we have problems with permanent zombie compartments. Mozilla Zombie compartments page gives only general information and just introduces into the problem and testing approaches.

So, i want to ask if somebody knows common bottlenecks and problematic design patterns (or simply, known bugs and fails) and best practices how to deal with them.

Added: Here is a good link of common causes of memory leaks in extensions. Any other suggestions?

2012-04-05 00:31
by gakhov


2

The most common failure mode is storing references to web pages for too long. This can happen for several reasons that I've seen:

  1. Assignment to global variables. Especially due to forgetting 'var'.
  2. Assignment to members of a global variable that you use to store your state and then not clearing it.
  3. Creating new function objects that close over the web page objects and then storing those functions somewhere (especially as event listeners) for a while.

Basically, any time you're working with something from a web page, make sure you never assign it to anything other than a local variable declared with var and that you don't create new long-lived functions closing over it. Those two things will help with a large fraction of cases.

Note that none of that is specific to Firefox extensions; it applies to all coding in JavaScript...

2012-04-05 04:10
by Boris Zbarsky
Yeah, these are very generic tips. For generic tips we have nice Using XPCOM in JavaScript without leaking page on Mozilla. Something more specific from the experience - gakhov 2012-04-05 10:22
Those are actually pretty specific. The "forgetting var" bit is one of the most common things I've seen people get wrong. Using strict mode is probably the simplest way to avoid that pitfall - Boris Zbarsky 2012-04-05 14:23
Since every serious extension uses a "strict" mode it's not really pitfall. I'm interesting in some tricky situation - gakhov 2012-04-05 16:58
Uh.. Plenty of "serious" extensions don't use strict mode. In any case, the most common "tricky" situation is #2 in my list. Storing state on an object and then not clearing it - Boris Zbarsky 2012-04-05 19:58
Ads