Why .data() function of jQuery is better to prevent memory leaks?
- by burak ozdogan
Hi,
Regarding to jQuery utility function jQuery.data() the online documentation says:
"The jQuery.data() method allows us to
attach data of any type to DOM
elements in a way that is safe from
circular references and therefore from
memory leaks. "
Why to use:
document.body.foo = 52;
can result a memory leak -or in what conditions- so that I should use
jQuery.data(document.body, 'foo', 52);
Should I ALWAYS prefer .data() instead of using expandos in any case?
(I would appreciate if you can provide an example to compare the differences)
Thanks,
burak ozdogan