Using MooTools this is something you don't have to worry about so much these days. It has its own garbage collection mechanisms. The important thing is that you always use the MooTools methods for selecting elements: $, $$, element.getElements, etc. But never document.getElementById, document.getElementByClassName. If you use those methods, you must wrap their results in $ and $$. So long as your elements are collected through mootools (or passed through $), they will be extended by MooTools and then garbage collected by MooTools.
On Thu, Apr 2, 2009 at 5:08 AM, electronbender (via Nabble) < [email protected]<ml-user%[email protected]> > wrote: > > I was just reading an article by Aaron about memory leaks, and > although he does say what is bad he does not say what is good. > So from the example this is bad: > function sayHi(observeId, message) { > var el = $(observeId); > Event.observe(el, "click", function() { > alert(message); > }); > } > > But what is good? > Is this: > function sayHi(observeId, message) { > Event.observe($(observeId), "click", function() { > alert(message); > }); > } > > Also, which of these 2 is good and which is bad: > var someEl = new Element('div',{'id':'someEl'}) > someEl.addEvent('click',function(){ > alert('bla') > }) > someEl.injectInside($(somediv)) > > Or this: > var someEl = new Element('div',{'id':'someEl'}) > someEl.injectInside($(somediv)) > > $('someEl').addEvent('click',function(){ > alert('bla') > }) > > > > ------------------------------ > View message @ > http://n2.nabble.com/-Moo--Memory-leaks-tp2574784p2574784.html > To start a new topic under MooTools Users, email > [email protected]<ml-node%[email protected]> > To unsubscribe from MooTools Users, click here< (link removed) >. > > > ----- The MooTools Tutorial: http://www.mootorial.com www.mootorial.com Clientcide: http://www.clientcide.com www.clientcide.com -- View this message in context: http://n2.nabble.com/-Moo--Memory-leaks-tp2574784p2576981.html Sent from the MooTools Users mailing list archive at Nabble.com.
