Does this javascript pattern encourage memory leaks?
<p>I am finding myself rather confused regarding javascript garbage collection and how to best encourage it.</p>

<p>What I would like to know is related to a particular pattern.  I am not interested in whether the pattern itself is considered a good or bad idea, I am simply interested in how a browsers garbage collector would respond, i.e would the references be freed and collected or would it cause leaks.</p>

<p>Imagine this pattern:</p>

<pre><code>   TEST = {     
                init : function(){                        
                      this.cache = {
                           element : $('#element')
                      };
                },
                func1 : function(){
                       this.cache.element.show();                     
                },
                func2 : function(){                                            
                       TEST.cache.element.show(); 
                },
                func3 : function(){
                       var self = this;                      
                       self.cache.element.show(); 
                },
                func4 : function(){
                       var element = this.cache.element;
                       element.show();
                }
                func5 : function(){
                        this.auxfunc(this.cache.element);
                }
                auxfunc1 : funtion(el){
                         el.show();
                }
                func6 : function(){
                       var el = getElement();
                       el.show();
                }
                getElement : function(){
                       return this.cache.element;
                }
    }
</code></pre>

<p>Now imagine that on page load <code>TEST.init()</code> is called;</p>

<p>Then later at various times the various functions are called.</p>

<p>What I would like to know is if caching elements or objects or anything else upon initialization and referring to them throughout the lifetime of an application, in the manner shown above, effects a browsers garbage collector positively or negatively.</p>

<p>Is there any difference?  Which method best encourages garbage collection?  Do they cause leaks? Are there any circular references? if so where?</p>

<p>Thanks in advance.</p>
