views:

62

answers:

1

I'm new to HTML5 application. And I'm making in-house software. This means I can force users to use only most recent version of firefox/webkit.

I saw many documents concerning about JS memory leaks in these point:

  1. Circular references.
  2. Event handlers.
  3. Closures.

As I think, it's just a problem of only (old version of) IE. But I cannot sure about this. So I'm asking do I have to address this issue in my situation. If I should, what's the solution, and what's the additional issues I have to care?

+1  A: 

Use a javascript library and you will be fine. jQuery makes it so you can have circular references, closures that refer back to jQuery objects, and event handlers that you never clean up. jQuery will automatically pick up all the pieces on unload if necessary and will also keep memory from leaking in any browser it supports.

If you are developing a JS-based application in which the page never (or rarely) refreshes, then you might have to worry about leaks, but they are easily overcommable by making plugins which have a deconstructors that destroys all member objects and dom elements. The jQuery .remove function removes the dom elements, the handlers, and anything else attatched to that element.

So just use a JS library and if you have to develop a lot of JS code, be careful and use a design pattern that is easy to clean up (like jQuery's plugin design pattern).

Bob Fincheimer
Thanks for reply. I heard of higher abstraction layer like jQuery/Cappuccino and etc. But I think I should learn about lowest-level before using them. If I don't know low-level, the abstraction layer will become untouchable black-box, and debugging will be full of pain.
Eonil
The problem with knowing the low-level is that you have to know how every browser treats the dom (which unfortunately every browser has a wildly different GC.). Although if you want to learn about just one browser, you can experiment and find the memory leaks. Firefox has a very good JS engine which I have never been able to leak between pages. However you can make it leak during usage of a page (like in a an all js/ajax app)...
Bob Fincheimer