Note that there are some explanatory texts on larger screens.

plurals
  1. POchange script element's src property to avoid memory leak in IE no longer works in IE9, IE10
    primarykey
    data
    text
    <p>With IE7 and IE8, I discovered one could avoid memory leaks in a "single page app" that was doing frequent JSONP calls by adding a script element to the head and simply changing the src attribute. Each time the src attribute was changed, it would immediately load and run the script. This is no longer working in IE9 or IE10. Using JQuery's .ajax() or manually where the previous script node is removed from the head, and a new one added (which works fine in FF and Chrome) causes memory to leak in IE.</p> <p>Here is the basic code I use to submit the JSONP - Jquery and other libraries seem to leak memory, I'm wondering if I can avoid it at all with ie9 and ie10...</p> <pre><code>// Some statics used by JSONP calls (below)... uuid is used to prevent getting stale cached results, it forces a new "get" every time by changing the url Testing123.uuid = 0; Testing123.head = document.getElementsByTagName('head')[0]; //----------------------------------------------------- // mainurl is the url we are going to, callbackFuncName is the callback function, parameters must be a string with zero or more parameters already encoded // formatted as "&amp;parm1=value1&amp;parm2=value2" as it is being tacked onto a GET url... Testing123.debugJSONP = false; // set to true to see stuff in console Testing123.initiateJSONP = function (mainurl, callbackFuncName, parameters) { var url = mainurl + "?callback=" + callbackFuncName + "&amp;uuid=" + (Testing123.uuid++); var script; url += parameters; // add optional parameters. // Now, let's make the JSONP call happen. One way for IE 8 and below, another way for FF, Chrome, etc. if (Testing123.isIE) { // ***** NOTE ***** // This tests for ALL ie versions, but ie9 and ie10 will only display one interation... // If you add &amp;&amp; Testing123.browserVersionNumber &lt; 9.0 to the if above, then the iterations will work, but // memory usage will go up dramatically if run for a while... // ***** NOTE ****** // For IE, we create the script node just once, and then set its src attribute to run again... // ***** This seems now to fail in ie9 and ie10 var addToDOM = 0; script = document.getElementById('JSONP'); if (!script) { if (Testing123.debugJSONP) Testing123.logToOutput("initiateJSONP with IE: creating script element with id JSONP"); script = document.createElement('script'); script.id = 'JSONP'; script.type = 'text/javascript'; script.charset = 'utf-8'; addToDOM = 1; } if (Testing123.debugJSONP) Testing123.logToOutput("initiateJSONP with IE: setting script element's src to " + url); script.setAttribute("src", url); //script.src = url; if (addToDOM) // Only do this the first time we create it... { if (Testing123.debugJSONP) Testing123.logToOutput("initiateJSONP with IE: appending script element with id JSONP to head"); Testing123.head.appendChild(script); } } else { //First lets clean up the DOM from the last call, if there was one... var tmp; while (tmp = document.getElementById('JSONP')) { if (Testing123.debugJSONP) Testing123.logToOutput("initiateJSONP non IE: found a JSONP element by id... asking parent to remove it and deleting its properties."); tmp.parentNode.removeChild(tmp); // not working in IE 7/8/9 for (var prop in tmp) { //if (Testing123.debugJSONP) Testing123.logToOutput("initiateJSONP non IE: deleting prop: [" + prop + "] from the element found."); delete tmp[prop]; } tmp = null; } </code></pre> <p>Does anyone have a solution to this issue? Here is a jsfiddle with a little test application and all the code:</p> <p><a href="http://jsfiddle.net/bbct/9RqZ6/" rel="nofollow">http://jsfiddle.net/bbct/9RqZ6/</a></p> <p>Thanks in advance for any advice / insight.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload