<?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: Leaking Memory in Java</title>
	<atom:link href="http://blog.xebia.com/2007/10/04/leaking-memory-in-java/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.xebia.com/2007/10/04/leaking-memory-in-java/</link>
	<description></description>
	<lastBuildDate>Thu, 11 Mar 2010 16:23:01 +0100</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Chris</title>
		<link>http://blog.xebia.com/2007/10/04/leaking-memory-in-java/comment-page-1/#comment-47108</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Tue, 08 Jul 2008 19:27:15 +0000</pubDate>
		<guid isPermaLink="false">http://blog.xebia.com/2007/10/04/leaking-memory-in-java/#comment-47108</guid>
		<description>I&#039;m leaving this for those who google to find...

To those saying its not a memory leak, you are being very strict with the term.  I, and others I know, have spent many man months of effort tracking down leaks due to this &quot;general&quot; use case.

Well, unfortunately, its not very general.  The problem is that any substring used (or split string used) will keep the whole block.  When splitting up large JMS text messages (for example) this will leave the entire message in memory, for an unspecified time.

It is a real problem that for a general algorithm you will get a leak like effect but not be warned of it in the javadocs.

User Beware.

</description>
		<content:encoded><![CDATA[<p>I&#8217;m leaving this for those who google to find&#8230;</p>
<p>To those saying its not a memory leak, you are being very strict with the term.  I, and others I know, have spent many man months of effort tracking down leaks due to this &#8220;general&#8221; use case.</p>
<p>Well, unfortunately, its not very general.  The problem is that any substring used (or split string used) will keep the whole block.  When splitting up large JMS text messages (for example) this will leave the entire message in memory, for an unspecified time.</p>
<p>It is a real problem that for a general algorithm you will get a leak like effect but not be warned of it in the javadocs.</p>
<p>User Beware.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan</title>
		<link>http://blog.xebia.com/2007/10/04/leaking-memory-in-java/comment-page-1/#comment-32025</link>
		<dc:creator>Ryan</dc:creator>
		<pubDate>Thu, 31 Jan 2008 06:37:31 +0000</pubDate>
		<guid isPermaLink="false">http://blog.xebia.com/2007/10/04/leaking-memory-in-java/#comment-32025</guid>
		<description>This is not a memory leak.  As Jos Hirth said, this is trading memory for speed.

As soon as you remove the substrings from the ArrayList all the memory that has been allocated for it will be freed.  No memory leak there.</description>
		<content:encoded><![CDATA[<p>This is not a memory leak.  As Jos Hirth said, this is trading memory for speed.</p>
<p>As soon as you remove the substrings from the ArrayList all the memory that has been allocated for it will be freed.  No memory leak there.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeroen van Erp</title>
		<link>http://blog.xebia.com/2007/10/04/leaking-memory-in-java/comment-page-1/#comment-19518</link>
		<dc:creator>Jeroen van Erp</dc:creator>
		<pubDate>Wed, 10 Oct 2007 06:36:31 +0000</pubDate>
		<guid isPermaLink="false">http://blog.xebia.com/2007/10/04/leaking-memory-in-java/#comment-19518</guid>
		<description>James,

True for String(char[] value, int offset, int count), but not for String(int offset, int count, char[] value). The constructor you mention is a public constructor. The constructor that is called from the substring method is a package private constructor.</description>
		<content:encoded><![CDATA[<p>James,</p>
<p>True for String(char[] value, int offset, int count), but not for String(int offset, int count, char[] value). The constructor you mention is a public constructor. The constructor that is called from the substring method is a package private constructor.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: creyle</title>
		<link>http://blog.xebia.com/2007/10/04/leaking-memory-in-java/comment-page-1/#comment-19506</link>
		<dc:creator>creyle</dc:creator>
		<pubDate>Tue, 09 Oct 2007 23:48:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.xebia.com/2007/10/04/leaking-memory-in-java/#comment-19506</guid>
		<description>To be more obvious, with the underlying big char array being referenced, all the TestGC objects created in the big for-loop could not be GCed. that&#039;s the problem.

Thanks</description>
		<content:encoded><![CDATA[<p>To be more obvious, with the underlying big char array being referenced, all the TestGC objects created in the big for-loop could not be GCed. that&#8217;s the problem.</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James McInosh</title>
		<link>http://blog.xebia.com/2007/10/04/leaking-memory-in-java/comment-page-1/#comment-19498</link>
		<dc:creator>James McInosh</dc:creator>
		<pubDate>Tue, 09 Oct 2007 21:07:29 +0000</pubDate>
		<guid isPermaLink="false">http://blog.xebia.com/2007/10/04/leaking-memory-in-java/#comment-19498</guid>
		<description>I don&#039;t know which version of the JVM you are sunning but when it constructs a new string using this constructor:

String(char value[], int offset, int count)

It sets the value using this:

this.value = Arrays.copyOfRange(value, offset, offset+count);</description>
		<content:encoded><![CDATA[<p>I don&#8217;t know which version of the JVM you are sunning but when it constructs a new string using this constructor:</p>
<p>String(char value[], int offset, int count)</p>
<p>It sets the value using this:</p>
<p>this.value = Arrays.copyOfRange(value, offset, offset+count);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: links for 2007-10-06 - smalls blogger</title>
		<link>http://blog.xebia.com/2007/10/04/leaking-memory-in-java/comment-page-1/#comment-19051</link>
		<dc:creator>links for 2007-10-06 - smalls blogger</dc:creator>
		<pubDate>Sat, 06 Oct 2007 00:45:50 +0000</pubDate>
		<guid isPermaLink="false">http://blog.xebia.com/2007/10/04/leaking-memory-in-java/#comment-19051</guid>
		<description>[...] Xebia Blog Leaking Memory in Java (tags: java memoryleak programming jvm) [...]</description>
		<content:encoded><![CDATA[<p>[...] Xebia Blog Leaking Memory in Java (tags: java memoryleak programming jvm) [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Randomly Intermittent Thoughts &#187; A Good Reasoning to Nullify an Object!</title>
		<link>http://blog.xebia.com/2007/10/04/leaking-memory-in-java/comment-page-1/#comment-19027</link>
		<dc:creator>Randomly Intermittent Thoughts &#187; A Good Reasoning to Nullify an Object!</dc:creator>
		<pubDate>Fri, 05 Oct 2007 20:33:10 +0000</pubDate>
		<guid isPermaLink="false">http://blog.xebia.com/2007/10/04/leaking-memory-in-java/#comment-19027</guid>
		<description>[...] Jos Hirth wrote this in response to this post by Jeroen van Erp. [...]</description>
		<content:encoded><![CDATA[<p>[...] Jos Hirth wrote this in response to this post by Jeroen van Erp. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jos Hirth</title>
		<link>http://blog.xebia.com/2007/10/04/leaking-memory-in-java/comment-page-1/#comment-18928</link>
		<dc:creator>Jos Hirth</dc:creator>
		<pubDate>Thu, 04 Oct 2007 23:30:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.xebia.com/2007/10/04/leaking-memory-in-java/#comment-18928</guid>
		<description>Well, that&#039;s not a memory leak. See:
http://en.wikipedia.org/wiki/Memory_leak

The behavior is intentional - it trades memory for performance. As most things in the standard library (eg collections) it&#039;s optimized for general usage and, well, generally it&#039;s alright. But you certainly shouldn&#039;t tokenize a really big string this way.

The classic type of memory leaks doesn&#039;t exist in managed languages. The only thing we can produce are so called reference leaks. That is... referencing stuff (and thus preventing em from being GCed) for longer as necessary (or for all eternity).

Fortunately it&#039;s easy to avoid - for the most part.

The important things to know:

Locally defined objects can be GCed as soon as there are no more no more references to it. Typically it&#039;s the end of the block they are defined in (if you don&#039;t store the reference anywhere). If you do store references, be sure to remove em if you don&#039;t need em anymore.

If you overwrite a reference with a new object, the object is first created and /then/ the reference is overwritten, which means the object can be only GCed /after/ the new object has been created.

Usually this doesn&#039;t matter. However, if you want to overwrite an object which is so big that it only fits once into the memory, you&#039;ll need to null the reference before creating/assigning the new instance.

Eg:
//FatObject fits only once into memory
FatObject fatty;
fatty=new FatObject();
fatty=new FatObject();

Will bomb with OOME. Whereas...

FatObject fatty;
fatty=new FatObject();
fatty=null;
fatty=new FatObject();

Will be fine, because the second creation of the FatObject will trigger a full GC and the GC will be able to clear enough memory (since the old reference has been nulled).

Well, that rarely matters, but it&#039;s good to know.</description>
		<content:encoded><![CDATA[<p>Well, that&#8217;s not a memory leak. See:<br />
<a href="http://en.wikipedia.org/wiki/Memory_leak" rel="nofollow">http://en.wikipedia.org/wiki/Memory_leak</a></p>
<p>The behavior is intentional &#8211; it trades memory for performance. As most things in the standard library (eg collections) it&#8217;s optimized for general usage and, well, generally it&#8217;s alright. But you certainly shouldn&#8217;t tokenize a really big string this way.</p>
<p>The classic type of memory leaks doesn&#8217;t exist in managed languages. The only thing we can produce are so called reference leaks. That is&#8230; referencing stuff (and thus preventing em from being GCed) for longer as necessary (or for all eternity).</p>
<p>Fortunately it&#8217;s easy to avoid &#8211; for the most part.</p>
<p>The important things to know:</p>
<p>Locally defined objects can be GCed as soon as there are no more no more references to it. Typically it&#8217;s the end of the block they are defined in (if you don&#8217;t store the reference anywhere). If you do store references, be sure to remove em if you don&#8217;t need em anymore.</p>
<p>If you overwrite a reference with a new object, the object is first created and /then/ the reference is overwritten, which means the object can be only GCed /after/ the new object has been created.</p>
<p>Usually this doesn&#8217;t matter. However, if you want to overwrite an object which is so big that it only fits once into the memory, you&#8217;ll need to null the reference before creating/assigning the new instance.</p>
<p>Eg:<br />
//FatObject fits only once into memory<br />
FatObject fatty;<br />
fatty=new FatObject();<br />
fatty=new FatObject();</p>
<p>Will bomb with OOME. Whereas&#8230;</p>
<p>FatObject fatty;<br />
fatty=new FatObject();<br />
fatty=null;<br />
fatty=new FatObject();</p>
<p>Will be fine, because the second creation of the FatObject will trigger a full GC and the GC will be able to clear enough memory (since the old reference has been nulled).</p>
<p>Well, that rarely matters, but it&#8217;s good to know.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sherif Mansour</title>
		<link>http://blog.xebia.com/2007/10/04/leaking-memory-in-java/comment-page-1/#comment-18894</link>
		<dc:creator>Sherif Mansour</dc:creator>
		<pubDate>Thu, 04 Oct 2007 12:04:20 +0000</pubDate>
		<guid isPermaLink="false">http://blog.xebia.com/2007/10/04/leaking-memory-in-java/#comment-18894</guid>
		<description>Hi There,
Thanks for the insightful article! I found this quite useful - especially in understanding why Java OutOfMemory&#039;s work...
Sherif</description>
		<content:encoded><![CDATA[<p>Hi There,<br />
Thanks for the insightful article! I found this quite useful &#8211; especially in understanding why Java OutOfMemory&#8217;s work&#8230;<br />
Sherif</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: GadgetGadget.info - Gadgets on the web &#187; Leaking Memory in Java</title>
		<link>http://blog.xebia.com/2007/10/04/leaking-memory-in-java/comment-page-1/#comment-18891</link>
		<dc:creator>GadgetGadget.info - Gadgets on the web &#187; Leaking Memory in Java</dc:creator>
		<pubDate>Thu, 04 Oct 2007 10:44:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.xebia.com/2007/10/04/leaking-memory-in-java/#comment-18891</guid>
		<description>[...] Devlib wrote an interesting post today!.Here&#8217;s a quick excerptNow however, in the days of Java, most people aren&#8217;t that concerned with memory leaks anymore. The common line of thought is that the Java Garbage Collector will take care of cleaning up behind you. This is of course totally true in all &#8230; [...]</description>
		<content:encoded><![CDATA[<p>[...] Devlib wrote an interesting post today!.Here&#8217;s a quick excerptNow however, in the days of Java, most people aren&#8217;t that concerned with memory leaks anymore. The common line of thought is that the Java Garbage Collector will take care of cleaning up behind you. This is of course totally true in all &#8230; [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
