title: Identify memory leak in this code while using startTimer and global variable
body: <p>I have this code in legacy application which gets generated via c# </p>
  
  <pre><code>string autoRefreshHandler = string.Format(null, "var autoRefresh = function() {{ {0}; }};", ClientScript.GetPostBackEventReference(postBackOptions));
          string autoRefreshMethod = string.Format(null, "setAutoRefreshTimeout({0}, autoRefresh);", refreshTime);
          string endRequestHandler = string.Format(null, @"function AutoRefreshEndRequestHandler(sender, args)
          {{
              var response = args.get_response();
              if (response &amp;&amp; response.get_responseAvailable())
              {{
                  // Request completed successfully. Reset Timer.
                  {0}
              }}
          }}", autoRefreshMethod);
          endRequestHandler += "Sys.WebForms.PageRequestManager.getInstance().add_endRequest(AutoRefreshEndRequestHandler);";
  </code></pre>
  
  <p>and it outputs as below:</p>
  
  <pre><code>var autoRefresh = function() {
      __doPostBack('ctl00$___AutoRefreshControl', '');
  };
  setAutoRefreshTimeout(60000, autoRefresh);
  
  function AutoRefreshEndRequestHandler(sender, args) {
      var response = args.get_response();
      if (response &amp;&amp; response.get_responseAvailable()) {
          // Request completed successfully. Reset Timer.
          setAutoRefreshTimeout(60000, autoRefresh);
      }
  }
  </code></pre>
  
  <p>The complete code would be something like this:</p>
  
  <pre><code>var autoRefresh = function() {
      __doPostBack('ctl00$___AutoRefreshControl', '');
  };
  setAutoRefreshTimeout(60000, autoRefresh);
  
  function AutoRefreshEndRequestHandler(sender, args) {
      var response = args.get_response();
      if (response &amp;&amp; response.get_responseAvailable()) {
          // Request completed successfully. Reset Timer.
          setAutoRefreshTimeout(60000, autoRefresh);
      }
  }
  
  function setAutoRefreshTimeout(timeOut, functionPointer) {
      clearAutoRefreshTimeout();
  
      autoRefreshTimeout = timeOut;
      autoRefreshFunction = functionPointer;
  
      autoRefreshTimer = startTimer(autoRefreshFunction, autoRefreshTimeout);
  
      timeOut = null;
      functionPointer = null;
  }
  
  function clearAutoRefreshTimeout() {
      clearTimer(autoRefreshTimer);
      autoRefreshTimer = null;
  }
  </code></pre>
  
  <p>I notice that this causes some memory leak(open chrome debugging tool or chrome task manger) and I am unable to understand why? Can someone help?</p>
  
  <p>I noticed in chrome Task Manager:</p>
  
  <pre><code>+-----------------+------------------+-----------+-------------+
  | MemoryFootprint | JavascriptMemory | LiveCount |             |
  +-----------------+------------------+-----------+-------------+
  |           70028 |            13565 |     10704 | First Load  |
  |           70460 |            13564 |  10588    | Second Load |
  +-----------------+------------------+-----------+-------------+
  </code></pre>