Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there memory leak in javascript of firefox/webkit? (except IE)

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?

like image 403
eonil Avatar asked Nov 06 '22 10:11

eonil


1 Answers

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).

like image 157
Bob Fincheimer Avatar answered Nov 11 '22 05:11

Bob Fincheimer