hi i have some troubles with memoryleaks in javascript. i'm using the Leak Memory 0.4.5 extension for firefox (https://addons.mozilla.org/de/firefox/addon/2490/) which shows me those javascript-objects which still remains in the memory. now i'm not sure how to correctly unbind dom-object from events etc. for instance: i have a jquery-widget called 'dropdownbox' in the destroy-methode i make all the necessary stuff to unbind event-handlers like:
this.box.find('.toggler').unbind();
this.box.remove();
this.box = null;
these 3 lines are a must, or is it possible to call only this.box.remove()?
till today i never have unbined or cleared something from dom-elements because i thought it doesn't matter. but i came up with the problem, that after 2 hours of developing on teh same site, my firefox consumes 1GB! so i read a bit of memory leaks when using closures etc. so thats my second question: i use very often closures because they are really cool and handy. some people say that you shouldn't use closures for everthing. so for example if we have the following code:
funtion foo(param1, param2) {
var local1, local2;
$('a').click(function() {
alert('YEAH');
});
}
it would be better to do it like:
funtion foo(param1, param2) {
var local1, local2;
$('a').click(clickEvent);
}
function() {
alert('YEAH');
}
or have i misunterstood that?