Re: JDOM and memory

Rolf Lear <[email protected]>
Newsgroups gmane.comp.java.jdom.general
Message-ID <[email protected]>
public class OOM {
	public static void main(String[] args) {
		int i = 0;
		String[] strings = new String[10000000];
		try {
			while (true) {
				i++;
				strings[i] = ("Number " + i).intern();
				if (0 == (i % 100000)) {
					System.out.println(strings[i]);
				}
			}
		} catch (Throwable t) {
			System.out.println("Last was " + i);
		}
	}
}


.....
Number 700000
Number 800000
Number 900000
Exception in thread "RMI TCP Connection(idle)" 
java.lang.OutOfMemoryError: PermGen space
Last was 984460


I had to store the result in the 'strings' array... I learned something 
... Java 6 does GC in the perm-gen space.... I watched it clearing out 
the values in the JVisualVM monitor.... but keeping a reference to the 
intern'd string causes OOM as expected.

In many places 1,000,000 strings is not a lot....

Rolf


On 28/01/2012 4:17 PM, Paul Libbrecht wrote:
> Interesting,
>
> the very first thing I did when writing OmdocJdom, a library with
> subclasses for each element type, is to use string-interning. I do not
> believe you can reach Out-Of-Memory by having such a diversity in
> element names, prefixes, etc... unless you are building a kind of super
> generic editor or modifier. 100Mb of strings is quite a lot (far more
> than all DTDs I've been touching thus far in my life I believe). We
> never ran into OOM for this (but with Lucene we did).
>
> paul
>
>
> Le 28 janv. 2012 à 20:42, Rolf Lear a écrit :
>
>> no, I have not compared against string-interning property. I was not
>> aware of that. But, reading the documentation, it says: All element
>> names, prefixes, attribute names, Namespace URIs, and local names are
>> internalized using java.lang.String.intern.
>>
>> This is *not* a good thing. String.intern() uses PermGen space to
>> intern the value (as if the value is a String constant in the code).
>> PermGen space is typically limited to a hundred or so megabytes. I
>> have, in the past, run in to significant issues where you get
>> OutOfMemory issues when String.intern is used liberally.... and
>> changing -Xmx makes no difference... very confusing the first time you
>> run in to that....
>>
>> So, I have not compared, to string-intern of the SAX parser. And I
>> would not recommend that people use that unless they know what they
>> are doing, and what sort of data they have.
>

_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.