<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Dynamic script generation and memory leaks</title>
	<atom:link href="http://ajaxian.com/archives/dynamic-script-generation-and-memory-leaks/feed" rel="self" type="application/rss+xml" />
	<link>http://ajaxian.com/archives/dynamic-script-generation-and-memory-leaks</link>
	<description>Cleaning up the web with Ajax</description>
	<lastBuildDate>Thu, 09 Feb 2012 06:55:33 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
	<item>
		<title>By: NeilFraser</title>
		<link>http://ajaxian.com/archives/dynamic-script-generation-and-memory-leaks/comment-page-1#comment-274872</link>
		<dc:creator>NeilFraser</dc:creator>
		<pubDate>Mon, 03 Aug 2009 20:27:22 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=7144#comment-274872</guid>
		<description>I&#039;m the Neil Fraser in question.  Let me address a few of your questions.

@Spocke and others, this is not specific to IE.  All browsers (IE, Firefox, Safari, Opera, Chrome) leak memory with this issue.  Deleting the properties on the script tag eliminates this leak in all browsers except IE, as IE doesn&#039;t let you delete native properties from DOM nodes.  However in IE (but not in any other browser) one can reuse the script tag simply by resetting the SRC attribute.  This important detail is mentioned in my article, but not in Ajaxian&#039;s summary.

@skippyK, This only affect script tags since script tags are unique in having footprints in both the DOM world and the JavaScript world.  The garbage collectors for each world don&#039;t work together, so they are unable to delete this node.  Normal nodes would (should) be cleaned up properly by the DOM&#039;s garbage collector.

@WebReflection, script.clearAttributes() only works in IE, and IE is the only browser which doesn&#039;t need this attribute pruning since the script tag can be reused.

@kissmyawesome, Other than in IE, I&#039;m not aware of any technique which alloows one to refire a JSONP script tag.

@lsn, 100% of the measurable leak was from the src attribute which in my case was very long.  The solution to delete all parameters and not just src was simply to be thorough.  Measurements were done under very controlled environments over eight hour periods with data points at half hour intervals.  The &#039;before&#039; graphs on all browsers showed linear growth, the &#039;after&#039; graphs on all browsers showed a flat line.

@kangax, there would normally only be one &#039;JSONP&#039; script tag, but in the off chance that there were more than one, this while loop would purge all of them.  The loop is for safety, not for design.</description>
		<content:encoded><![CDATA[<p>I&#8217;m the Neil Fraser in question.  Let me address a few of your questions.</p>
<p>@Spocke and others, this is not specific to IE.  All browsers (IE, Firefox, Safari, Opera, Chrome) leak memory with this issue.  Deleting the properties on the script tag eliminates this leak in all browsers except IE, as IE doesn&#8217;t let you delete native properties from DOM nodes.  However in IE (but not in any other browser) one can reuse the script tag simply by resetting the SRC attribute.  This important detail is mentioned in my article, but not in Ajaxian&#8217;s summary.</p>
<p>@skippyK, This only affect script tags since script tags are unique in having footprints in both the DOM world and the JavaScript world.  The garbage collectors for each world don&#8217;t work together, so they are unable to delete this node.  Normal nodes would (should) be cleaned up properly by the DOM&#8217;s garbage collector.</p>
<p>@WebReflection, script.clearAttributes() only works in IE, and IE is the only browser which doesn&#8217;t need this attribute pruning since the script tag can be reused.</p>
<p>@kissmyawesome, Other than in IE, I&#8217;m not aware of any technique which alloows one to refire a JSONP script tag.</p>
<p>@lsn, 100% of the measurable leak was from the src attribute which in my case was very long.  The solution to delete all parameters and not just src was simply to be thorough.  Measurements were done under very controlled environments over eight hour periods with data points at half hour intervals.  The &#8216;before&#8217; graphs on all browsers showed linear growth, the &#8216;after&#8217; graphs on all browsers showed a flat line.</p>
<p>@kangax, there would normally only be one &#8216;JSONP&#8217; script tag, but in the off chance that there were more than one, this while loop would purge all of them.  The loop is for safety, not for design.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jdalton</title>
		<link>http://ajaxian.com/archives/dynamic-script-generation-and-memory-leaks/comment-page-1#comment-274768</link>
		<dc:creator>jdalton</dc:creator>
		<pubDate>Thu, 30 Jul 2009 02:48:19 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=7144#comment-274768</guid>
		<description>@lsn I don&#039;t believe discussing fixes for an issue that has been proven, in at least IE, is `missing the mark`. I haven&#039;t seen proof of it effecting other browsers but using the dummy element + innerHTML solution won&#039;t throw compat issues with other browsers. I may assume by your skepticism that a YUI patch, even to solve the IE issue, will not be coming any time soon :(</description>
		<content:encoded><![CDATA[<p>@lsn I don&#8217;t believe discussing fixes for an issue that has been proven, in at least IE, is `missing the mark`. I haven&#8217;t seen proof of it effecting other browsers but using the dummy element + innerHTML solution won&#8217;t throw compat issues with other browsers. I may assume by your skepticism that a YUI patch, even to solve the IE issue, will not be coming any time soon :(</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kangax</title>
		<link>http://ajaxian.com/archives/dynamic-script-generation-and-memory-leaks/comment-page-1#comment-274764</link>
		<dc:creator>kangax</dc:creator>
		<pubDate>Wed, 29 Jul 2009 22:11:08 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=7144#comment-274764</guid>
		<description>&lt;cite&gt;while (script = document.getElementById(&#039;JSONP&#039;))&lt;/cite&gt;
Please don&#039;t promote such thing. id&#039;s should be unique in a document. Assigning same &quot;JSONP&quot; id to every SCRIPT element is definitely not how it&#039;s &quot;normally done&quot;.</description>
		<content:encoded><![CDATA[<p><cite>while (script = document.getElementById(&#8216;JSONP&#8217;))</cite><br />
Please don&#8217;t promote such thing. id&#8217;s should be unique in a document. Assigning same &#8220;JSONP&#8221; id to every SCRIPT element is definitely not how it&#8217;s &#8220;normally done&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lsn</title>
		<link>http://ajaxian.com/archives/dynamic-script-generation-and-memory-leaks/comment-page-1#comment-274743</link>
		<dc:creator>lsn</dc:creator>
		<pubDate>Wed, 29 Jul 2009 17:16:55 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=7144#comment-274743</guid>
		<description>Two important points:
1) The article states
&lt;blockquote cite=&quot;http://neil.fraser.name/news/2009/07/27/&quot;&gt;every one of today&#039;s browsers will fail to garbage collect the offending node&lt;/blockquote&gt; so all the discussion about IE specific solutions are missing the mark
2) The article provides no proof, only the assertion.  The claim that &lt;strong&gt;every&lt;/strong&gt; attribute must be removed from the script nodes suggests to me that not enough debugging was done.  Surely if his claim is legit, only one or a handful of attributes should be removed.  Without visibility into the system that had the leak, we&#039;re left to believe him or (dis)prove his assertion.

At best, this article should be a suggestion/warning that some investigation (and detailed documentation) needs to be put into the real effects and side effects of using generated script nodes.  Discovering new dhtml issues is great and helpful to web devs everywhere, but let&#039;s be sure of the issue.</description>
		<content:encoded><![CDATA[<p>Two important points:<br />
1) The article states</p>
<blockquote cite="http://neil.fraser.name/news/2009/07/27/"><p>every one of today&#8217;s browsers will fail to garbage collect the offending node</p></blockquote>
<p> so all the discussion about IE specific solutions are missing the mark<br />
2) The article provides no proof, only the assertion.  The claim that <strong>every</strong> attribute must be removed from the script nodes suggests to me that not enough debugging was done.  Surely if his claim is legit, only one or a handful of attributes should be removed.  Without visibility into the system that had the leak, we&#8217;re left to believe him or (dis)prove his assertion.</p>
<p>At best, this article should be a suggestion/warning that some investigation (and detailed documentation) needs to be put into the real effects and side effects of using generated script nodes.  Discovering new dhtml issues is great and helpful to web devs everywhere, but let&#8217;s be sure of the issue.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jdalton</title>
		<link>http://ajaxian.com/archives/dynamic-script-generation-and-memory-leaks/comment-page-1#comment-274737</link>
		<dc:creator>jdalton</dc:creator>
		<pubDate>Wed, 29 Jul 2009 14:28:23 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=7144#comment-274737</guid>
		<description>Another way to fix the IE issue with removeChild() without looping through attributes from way back in 2007 http://blogs.telerik.com/toddanglin/posts/07-03-26/the_ajax_papers_part_ii.aspx.
.
jQuery thread exploring the use of outerHTML instead of innerHTML
http://groups.google.com/group/jquery-dev/browse_thread/thread/4a99f6e9b2e33057/45ce657a48afd43a?#45ce657a48afd43a</description>
		<content:encoded><![CDATA[<p>Another way to fix the IE issue with removeChild() without looping through attributes from way back in 2007 <a href="http://blogs.telerik.com/toddanglin/posts/07-03-26/the_ajax_papers_part_ii.aspx" rel="nofollow">http://blogs.telerik.com/toddanglin/posts/07-03-26/the_ajax_papers_part_ii.aspx</a>.<br />
.<br />
jQuery thread exploring the use of outerHTML instead of innerHTML<br />
<a href="http://groups.google.com/group/jquery-dev/browse_thread/thread/4a99f6e9b2e33057/45ce657a48afd43a?#45ce657a48afd43a" rel="nofollow">http://groups.google.com/group/jquery-dev/browse_thread/thread/4a99f6e9b2e33057/45ce657a48afd43a?#45ce657a48afd43a</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: paziek</title>
		<link>http://ajaxian.com/archives/dynamic-script-generation-and-memory-leaks/comment-page-1#comment-274734</link>
		<dc:creator>paziek</dc:creator>
		<pubDate>Wed, 29 Jul 2009 11:00:25 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=7144#comment-274734</guid>
		<description>Why are u providing solutions to an issue that is not ours?
This is the very reason why we still have IE around and need to use so many workarounds. You are suggesting to add more and let MS continue piss us off with their crappy software.
Then, you proceed to whine how users are stupid for using IE, but in reality stupid are we for ever creating workarounds for this piece of guano.</description>
		<content:encoded><![CDATA[<p>Why are u providing solutions to an issue that is not ours?<br />
This is the very reason why we still have IE around and need to use so many workarounds. You are suggesting to add more and let MS continue piss us off with their crappy software.<br />
Then, you proceed to whine how users are stupid for using IE, but in reality stupid are we for ever creating workarounds for this piece of guano.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kissmyawesome</title>
		<link>http://ajaxian.com/archives/dynamic-script-generation-and-memory-leaks/comment-page-1#comment-274733</link>
		<dc:creator>kissmyawesome</dc:creator>
		<pubDate>Wed, 29 Jul 2009 10:41:20 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=7144#comment-274733</guid>
		<description>Would a better option not be to just re-use the nodes? If you&#039;re injecting via JSONP, then you can easily wrap your callback in a bit of extra code to manage nodes that have returned their payload and can therefore be reused.</description>
		<content:encoded><![CDATA[<p>Would a better option not be to just re-use the nodes? If you&#8217;re injecting via JSONP, then you can easily wrap your callback in a bit of extra code to manage nodes that have returned their payload and can therefore be reused.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: WebReflection</title>
		<link>http://ajaxian.com/archives/dynamic-script-generation-and-memory-leaks/comment-page-1#comment-274732</link>
		<dc:creator>WebReflection</dc:creator>
		<pubDate>Wed, 29 Jul 2009 10:06:21 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=7144#comment-274732</guid>
		<description>call it purge then, destroy was from Ext JS convention and nothing else. I hope you got the point that we do not need manual for loops to remove properties in IE or a delete which could cause an exception. In few words, this post is suggesting a bad practice, without providing a valid solution, imho.</description>
		<content:encoded><![CDATA[<p>call it purge then, destroy was from Ext JS convention and nothing else. I hope you got the point that we do not need manual for loops to remove properties in IE or a delete which could cause an exception. In few words, this post is suggesting a bad practice, without providing a valid solution, imho.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: steida</title>
		<link>http://ajaxian.com/archives/dynamic-script-generation-and-memory-leaks/comment-page-1#comment-274731</link>
		<dc:creator>steida</dc:creator>
		<pubDate>Wed, 29 Jul 2009 09:59:40 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=7144#comment-274731</guid>
		<description>I just corrected your statement &lt;cite&gt;suggested for every DOM node&lt;/cite&gt; which was wrong and still is :). 
btw, it&#039;s my opinion, but I don&#039;t like name &quot;destroy&quot;. In JS you can never ensure that element will be really destroyed. There is no such thing like destructor in JS. &quot;Purge&quot; would be a better name.</description>
		<content:encoded><![CDATA[<p>I just corrected your statement <cite>suggested for every DOM node</cite> which was wrong and still is :).<br />
btw, it&#8217;s my opinion, but I don&#8217;t like name &#8220;destroy&#8221;. In JS you can never ensure that element will be really destroyed. There is no such thing like destructor in JS. &#8220;Purge&#8221; would be a better name.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: WebReflection</title>
		<link>http://ajaxian.com/archives/dynamic-script-generation-and-memory-leaks/comment-page-1#comment-274730</link>
		<dc:creator>WebReflection</dc:creator>
		<pubDate>Wed, 29 Jul 2009 09:56:28 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=7144#comment-274730</guid>
		<description>P.S. before some other comment, this is for IE only which means other browsers do not need it. I am updating the script in my blog to make things more simple for everybody ....</description>
		<content:encoded><![CDATA[<p>P.S. before some other comment, this is for IE only which means other browsers do not need it. I am updating the script in my blog to make things more simple for everybody &#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: WebReflection</title>
		<link>http://ajaxian.com/archives/dynamic-script-generation-and-memory-leaks/comment-page-1#comment-274729</link>
		<dc:creator>WebReflection</dc:creator>
		<pubDate>Wed, 29 Jul 2009 09:46:41 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=7144#comment-274729</guid>
		<description>steida, isn&#039;t this post related to a script node? Have you read my entry? Quick summary for lazy guys:
&lt;code&gt;
function destroy(node){
    // WebReflection IE leak attemp!
    if(node.attributes)
        node.clearAttributes(); // Hedger suggestion
    while(node.lastChild)
        destroy(node.lastChild);
    if(node.parentNode)
        node.parentNode.removeChild(node);
};
&lt;/code&gt;

Regards</description>
		<content:encoded><![CDATA[<p>steida, isn&#8217;t this post related to a script node? Have you read my entry? Quick summary for lazy guys:<br />
<code><br />
function destroy(node){<br />
    // WebReflection IE leak attemp!<br />
    if(node.attributes)<br />
        node.clearAttributes(); // Hedger suggestion<br />
    while(node.lastChild)<br />
        destroy(node.lastChild);<br />
    if(node.parentNode)<br />
        node.parentNode.removeChild(node);<br />
};<br />
</code></p>
<p>Regards</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: steida</title>
		<link>http://ajaxian.com/archives/dynamic-script-generation-and-memory-leaks/comment-page-1#comment-274728</link>
		<dc:creator>steida</dc:creator>
		<pubDate>Wed, 29 Jul 2009 09:17:16 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=7144#comment-274728</guid>
		<description>@WebReflection, clearAttributes doesn&#039;t work for every DOM node. Only for elements which has that method.</description>
		<content:encoded><![CDATA[<p>@WebReflection, clearAttributes doesn&#8217;t work for every DOM node. Only for elements which has that method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nosredna</title>
		<link>http://ajaxian.com/archives/dynamic-script-generation-and-memory-leaks/comment-page-1#comment-274726</link>
		<dc:creator>Nosredna</dc:creator>
		<pubDate>Tue, 28 Jul 2009 22:56:29 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=7144#comment-274726</guid>
		<description>@Spocke, I don&#039;t know that people think that way. You might as well imagine that people will soon stop having dogs because dogs poop.</description>
		<content:encoded><![CDATA[<p>@Spocke, I don&#8217;t know that people think that way. You might as well imagine that people will soon stop having dogs because dogs poop.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: skippyK</title>
		<link>http://ajaxian.com/archives/dynamic-script-generation-and-memory-leaks/comment-page-1#comment-274724</link>
		<dc:creator>skippyK</dc:creator>
		<pubDate>Tue, 28 Jul 2009 22:23:07 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=7144#comment-274724</guid>
		<description>I don&#039;t understand why this is unique to JSONP. Shouldn&#039;t any DOM node you delete suffer the same leaks?</description>
		<content:encoded><![CDATA[<p>I don&#8217;t understand why this is unique to JSONP. Shouldn&#8217;t any DOM node you delete suffer the same leaks?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Spocke</title>
		<link>http://ajaxian.com/archives/dynamic-script-generation-and-memory-leaks/comment-page-1#comment-274721</link>
		<dc:creator>Spocke</dc:creator>
		<pubDate>Tue, 28 Jul 2009 21:26:24 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=7144#comment-274721</guid>
		<description>Interessting stuff. I think one of the good things with all these memory leaks on IE is that less and less people will use it since it will clog up with complex applications written by users not testing for memory leaks. So in a sense in a few years the old leaky IE versions might be rendered useless even if people do cross browser logic.</description>
		<content:encoded><![CDATA[<p>Interessting stuff. I think one of the good things with all these memory leaks on IE is that less and less people will use it since it will clog up with complex applications written by users not testing for memory leaks. So in a sense in a few years the old leaky IE versions might be rendered useless even if people do cross browser logic.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

