Why .data() function of jQuery is better to prevent memory leaks?
        Posted  
        
            by burak ozdogan
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by burak ozdogan
        
        
        
        Published on 2010-04-30T12:09:48Z
        Indexed on 
            2010/04/30
            12:27 UTC
        
        
        Read the original article
        Hit count: 374
        
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
© Stack Overflow or respective owner