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.

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.

On Thu, Jan 6, 2011 at 11:28 AM, james <[email protected]> wrote:

> So basically I have an onDestroy() that I call on my objects. It
> easier to keep track of your references in a small object so calling
> onDestroy on the objects when I know I am done with them provides a
> nice way to clean up.


For applications meant to run longer I did add a garbage mechanism. But for
the wrapper, adding garbage mechanisms added a very thick layer of
complexity. In most cases it's not worth it.

Note that the future version of js might have a mechanism that'll make this
system a lot easier...
http://wiki.ecmascript.org/doku.php?id=harmony:weak_maps

- peter

-- 
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]

Reply via email to