ghegstrom
unread,Aug 30, 2011, 11:04:42 AM8/30/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to testng-dev
I am seeing out of memory issues with a particularly large XML report.
[testng] Exception in thread "main" java.lang.OutOfMemoryError:
Java heap space
[testng] at java.util.Arrays.copyOf(Arrays.java:2882)
[testng] at
java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:
100)
[testng] at
java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:572)
[testng] at java.lang.StringBuilder.append(StringBuilder.java:
203)
[testng] at
org.testng.internal.Utils.escapeUnicode(Utils.java:548)
[testng] at
org.testng.internal.Utils.writeUtf8File(Utils.java:113)
[testng] at
org.testng.reporters.XMLReporter.generateReport(XMLReporter.java:65)
[testng] at org.testng.TestNG.generateReports(TestNG.java:
1053)
[testng] at org.testng.TestNG.run(TestNG.java:1016)
[testng] at org.testng.TestNG.privateMain(TestNG.java:1301)
[testng] at org.testng.TestNG.main(TestNG.java:1265)
[testng] The tests failed.
Looking at Utils.java, I noticed that escapeUnicode() has the
following line (543):
StringBuilder result = new StringBuilder();
I think the resulting string will always be at least as long as the
input string, so it seems like that line should be changed to:
StringBuilder result = new StringBuilder(s.Length());
That should prevent 17 or so reallocations and mem_copies when the
string is around 1 MB in size.
Of course, whether we should have a file that big is a different
question, and obviously I can increase the available memory, but
initializing the StringBuilder to a known size seems more efficient
regardless.
Thanks,
-Greg