<?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: Myth busting &#8211; String.intern() object allocations are never garbage collected</title>
	<atom:link href="http://www.javatuning.com/myth-busting-string-intern-object-allocations-are-never-garbage-collected/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javatuning.com/myth-busting-string-intern-object-allocations-are-never-garbage-collected/</link>
	<description>Software Development, Java, and some more.</description>
	<lastBuildDate>Tue, 15 Nov 2011 03:25:30 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Eishay Smith</title>
		<link>http://www.javatuning.com/myth-busting-string-intern-object-allocations-are-never-garbage-collected/comment-page-1/#comment-1700</link>
		<dc:creator>Eishay Smith</dc:creator>
		<pubDate>Sat, 13 Mar 2010 16:41:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.javatuning.com/?p=212#comment-1700</guid>
		<description>Yes, there are lots of myths are there like 64bit machines are better then 32bit, one GC is better then the other, IO myths, and so on. The common answer is &quot;it depends&quot; since one size does *not* fit all.

All large scale software should have limits on in memory data growth. Almost every web framework limits the number of concurrent sessions per server, usually by limiting size of thread pool accepting inbound connections.

If you have an in memory map used as a cache where you can discard some of the data if it gets too large then check out Ehcache and you might want to get distributed with memcached since the network is very IO cheap (all depends on your required latencies and cost of computing new values).
Creating a java new object by itself is cheap and keeping many long term objects is a burden on the system&#039;s memory management. Given that, I would not throw cache (and string intern is a type of cache) without getting some numbers first.</description>
		<content:encoded><![CDATA[<p>Yes, there are lots of myths are there like 64bit machines are better then 32bit, one GC is better then the other, IO myths, and so on. The common answer is &#8220;it depends&#8221; since one size does *not* fit all.</p>
<p>All large scale software should have limits on in memory data growth. Almost every web framework limits the number of concurrent sessions per server, usually by limiting size of thread pool accepting inbound connections.</p>
<p>If you have an in memory map used as a cache where you can discard some of the data if it gets too large then check out Ehcache and you might want to get distributed with memcached since the network is very IO cheap (all depends on your required latencies and cost of computing new values).<br />
Creating a java new object by itself is cheap and keeping many long term objects is a burden on the system&#8217;s memory management. Given that, I would not throw cache (and string intern is a type of cache) without getting some numbers first.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gili Nachum</title>
		<link>http://www.javatuning.com/myth-busting-string-intern-object-allocations-are-never-garbage-collected/comment-page-1/#comment-1699</link>
		<dc:creator>Gili Nachum</dc:creator>
		<pubDate>Sat, 13 Mar 2010 13:13:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.javatuning.com/?p=212#comment-1699</guid>
		<description>Main main aim was to point out that something common wisdom that was true yesterday may not still hold true today. Especially things that concern low level stuff, that were likely to get attention from the JVM development team as time goes by. Also have to keep in mind that what can/can&#039;t be done is JVM implementation/version specific.

From what Eishay is saying, it sounds like that even though the garbage collector has a solid foothold in the perm area, it&#039;s still not completely trivial.
If I would to make extensive intern usage, I&#039;ll make sure I have time to tune the GC perm area during stress testing plus a back of the envelope calculation on how many String I&#039;m expecting to place in the perm area, making sure enough space is left for everything except interened Strings.

BTW, in my current project we employ hard limits on the number of sessions and users as a mean to protect against out of memory situations. Seen/implemented something like that in any of the projects you&#039;ve worked on?
I also like to put caps and report if any map/list grows beyond a certain limit. especially maps used as a temporal storage to preserve information between two executions. Provided useful to warn about memory leaks. Something like:

if (ht.size()&gt;10000) {
  System.out.println(&quot;WARNING: ht size above 10K, purging it.&quot;);
  ht.clean();
}
  ht.put(key, value);</description>
		<content:encoded><![CDATA[<p>Main main aim was to point out that something common wisdom that was true yesterday may not still hold true today. Especially things that concern low level stuff, that were likely to get attention from the JVM development team as time goes by. Also have to keep in mind that what can/can&#8217;t be done is JVM implementation/version specific.</p>
<p>From what Eishay is saying, it sounds like that even though the garbage collector has a solid foothold in the perm area, it&#8217;s still not completely trivial.<br />
If I would to make extensive intern usage, I&#8217;ll make sure I have time to tune the GC perm area during stress testing plus a back of the envelope calculation on how many String I&#8217;m expecting to place in the perm area, making sure enough space is left for everything except interened Strings.</p>
<p>BTW, in my current project we employ hard limits on the number of sessions and users as a mean to protect against out of memory situations. Seen/implemented something like that in any of the projects you&#8217;ve worked on?<br />
I also like to put caps and report if any map/list grows beyond a certain limit. especially maps used as a temporal storage to preserve information between two executions. Provided useful to warn about memory leaks. Something like:</p>
<p>if (ht.size()>10000) {<br />
  System.out.println(&#8220;WARNING: ht size above 10K, purging it.&#8221;);<br />
  ht.clean();<br />
}<br />
  ht.put(key, value);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eishay Smith</title>
		<link>http://www.javatuning.com/myth-busting-string-intern-object-allocations-are-never-garbage-collected/comment-page-1/#comment-1698</link>
		<dc:creator>Eishay Smith</dc:creator>
		<pubDate>Thu, 11 Mar 2010 17:22:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.javatuning.com/?p=212#comment-1698</guid>
		<description>Thanks Eyal, this is pretty cool, didn&#039;t know about this option.</description>
		<content:encoded><![CDATA[<p>Thanks Eyal, this is pretty cool, didn&#8217;t know about this option.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eyal</title>
		<link>http://www.javatuning.com/myth-busting-string-intern-object-allocations-are-never-garbage-collected/comment-page-1/#comment-1697</link>
		<dc:creator>Eyal</dc:creator>
		<pubDate>Thu, 11 Mar 2010 17:00:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.javatuning.com/?p=212#comment-1697</guid>
		<description>I think you can enable perm gen cleaning on cms

CMSPermGenSweepingEnabled</description>
		<content:encoded><![CDATA[<p>I think you can enable perm gen cleaning on cms</p>
<p>CMSPermGenSweepingEnabled</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eishay Smith</title>
		<link>http://www.javatuning.com/myth-busting-string-intern-object-allocations-are-never-garbage-collected/comment-page-1/#comment-1696</link>
		<dc:creator>Eishay Smith</dc:creator>
		<pubDate>Thu, 11 Mar 2010 15:29:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.javatuning.com/?p=212#comment-1696</guid>
		<description>In some cases you still want to avoid String interns. Java allocates the memory to the interned strings on the permgen space. If you have a very heavy application with tons of classes (I had some like these), the classes are competing with the interned strings on the space. While the GC does clean up the permgen space, it does it only in a &quot;stop the world&quot; GC and not in a CMS which you typically configure your webapp or desktop to. The problem is more typical to web application where you may have very large heaps and very high object creation rate. If the GC is being called on the permgen too often it will eventually throw out of permgen space exceptions (seen it as well).

So the final answer is &quot;it depends&quot; :-)
I would still recommend not to use intern in the common application though there are few edge cases where it would make sense.</description>
		<content:encoded><![CDATA[<p>In some cases you still want to avoid String interns. Java allocates the memory to the interned strings on the permgen space. If you have a very heavy application with tons of classes (I had some like these), the classes are competing with the interned strings on the space. While the GC does clean up the permgen space, it does it only in a &#8220;stop the world&#8221; GC and not in a CMS which you typically configure your webapp or desktop to. The problem is more typical to web application where you may have very large heaps and very high object creation rate. If the GC is being called on the permgen too often it will eventually throw out of permgen space exceptions (seen it as well).</p>
<p>So the final answer is &#8220;it depends&#8221; <img src='http://www.javatuning.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /><br />
I would still recommend not to use intern in the common application though there are few edge cases where it would make sense.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gili Nachum</title>
		<link>http://www.javatuning.com/myth-busting-string-intern-object-allocations-are-never-garbage-collected/comment-page-1/#comment-1695</link>
		<dc:creator>Gili Nachum</dc:creator>
		<pubDate>Mon, 08 Mar 2010 16:44:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.javatuning.com/?p=212#comment-1695</guid>
		<description>Eyal, you seem to be right!

I&#039;ve checked on both IBM Java5 and IBM Java6. 
Both loop and multi-lines concatenations turn into a StringBuilder.
Seems like there are less and less reasons to micro tune your code.
Thanks.

------------------------------------------------
concatenating in a loop - Javap will show you StringBuilder
------------------------------------------------
public static volatile String s = &quot;&quot;;
	public static void main(String[] args) throws InterruptedException {
		for (int i=0; i&lt;10; i++) {
			String strOfThisCycle = String.valueOf(i);
			s += strOfThisCycle;
			}
	}

------------------------------------------------
Concatenating over multiple lines - Javap will show you StringBuilder
------------------------------------------------
public static void main(String[] args) throws InterruptedException {
			String strOfThisCycle = &quot;0&quot;;
			s += strOfThisCycle;
			strOfThisCycle = String.valueOf(System.currentTimeMillis());
			s += strOfThisCycle;
	}</description>
		<content:encoded><![CDATA[<p>Eyal, you seem to be right!</p>
<p>I&#8217;ve checked on both IBM Java5 and IBM Java6.<br />
Both loop and multi-lines concatenations turn into a StringBuilder.<br />
Seems like there are less and less reasons to micro tune your code.<br />
Thanks.</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
concatenating in a loop &#8211; Javap will show you StringBuilder<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
public static volatile String s = &#8220;&#8221;;<br />
	public static void main(String[] args) throws InterruptedException {<br />
		for (int i=0; i&lt;10; i++) {<br />
			String strOfThisCycle = String.valueOf(i);<br />
			s += strOfThisCycle;<br />
			}<br />
	}</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Concatenating over multiple lines &#8211; Javap will show you StringBuilder<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
public static void main(String[] args) throws InterruptedException {<br />
			String strOfThisCycle = &#8220;0&#8243;;<br />
			s += strOfThisCycle;<br />
			strOfThisCycle = String.valueOf(System.currentTimeMillis());<br />
			s += strOfThisCycle;<br />
	}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eyal</title>
		<link>http://www.javatuning.com/myth-busting-string-intern-object-allocations-are-never-garbage-collected/comment-page-1/#comment-1694</link>
		<dc:creator>Eyal</dc:creator>
		<pubDate>Mon, 08 Mar 2010 13:34:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.javatuning.com/?p=212#comment-1694</guid>
		<description>Hi,

In java 6 I think that if you run javap on the for loop example you will
see that it uses StringBuilder also, But I might be mistaken :-)

Eyal</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>In java 6 I think that if you run javap on the for loop example you will<br />
see that it uses StringBuilder also, But I might be mistaken <img src='http://www.javatuning.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Eyal</p>
]]></content:encoded>
	</item>
</channel>
</rss>

