On Jan 6, 10:28 pm, Bryan Forbes <[email protected]> wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On 1/6/11 4:47 AM, Peter van der Zee wrote: > > > Actually there was some discussion on twitter related to this. Jed drew > > a simple conclusion; expando's win in speed from alternative > > methods.http://twitter.com/jedschmidt/status/22784074045198338 > > > The way I solved the leak pattern at some point was to use the expando > > pattern and store the referenced objects in an array. The object would > > then get a unique property (something like ._id usually suffices, but > > the property name itself is not very important) to point to the correct > > index in the reference array. > > So, you would do something like this when attaching the initial event, > right?: > > if(typeof elem._id == "undefined"){ > elem._id = generateEventHandlerID(); > > } > > I didn't go into it in the article, but IE has a property on every > created node called `uniqueNumber`: > > http://msdn.microsoft.com/en-us/library/ff628957(VS.85).aspx >
Both "uniqueID" and "uniqueNumber" properties are available in Internet Explorer. http://msdn.microsoft.com/en-us/library/ms534704(v=vs.85).aspx They are very useful to maintain other data/handlers bound to elements without creating expandos or new properties on the elements themselves. -- Diego > FuseJS does something similar to what you're doing, but on Internet > Explorer it uses elem.uniqueNumber to keep from having an expando that > would be copied when cloning an element: > > https://github.com/jdalton/fusejs/blob/e5c1c4c09ed5fb6ea0e5cb2bbebc36... > > I've taken the same approach in uber.js. If you can avoid expandos in > IE, you should. > > > This will prevent most leaks right there. In events or wrappers you use > > the $.getId(el._id) method, reference it immediately (or in another > > similar way that you know won't stick and leak) and prevent the leakage > > completely because it's never actually stored in your event/wrapper. > > > When time comes and the user navigates away, all you have to do is > > delete the array onbeforeunload and all references will be released at once. > > Attaching an `onbeforeunload` handler will break bfcache: > > https://developer.mozilla.org/En/Using_Firefox_1.5_caching > > If you have a massive application, it would probably be best not to have > to re-initialize (reparse the DOM, etc.) it when navigating back to it. > > - -- > Bryan Forbeshttp://www.reigndropsfall.net > > GPG Fingerprint > 3D7D B728 713A BB7B B8B1 5B61 3888 17E0 70CA 0F3D > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.11 (Darwin) > Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org/ > > iEYEARECAAYFAk0mM/cACgkQOIgX4HDKDz2AVwCgwnmR91GTs6+x+gfCzuqGil7m > AhMAn1FxI5QzXN8xGUCVaJdVvrYLkV4W > =LApk > -----END PGP SIGNATURE----- -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/[email protected]/ To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/ To unsubscribe from this group, send email to [email protected]
