這是在eclipsepowered上看到的。 Ed提到了eclipse-dev committers mailing list中,Jerome Lanneluc 指出的一個String#substring和String(String)的問題。按照Jerome的說法,使用String#substring()的時候,原有的長字符串所占據的空間仍然被占據,并沒有釋放,使用String(String)可以解決這個問題。Jerome的原文:
I just noticed that String#substring(…) shares the underlying char array. So if you have a big string, take a substring of it, throw away the big string, you will still hold on the big char array. A simple way to solve this is to make a copy of the substring using the String(String) constructor.
I saved 550KB in JDT Core by changing the following code:
String simpleName =
fullyQualifiedName.substring(fullQualifiedName.lastIndexOf('.'));
to
String simpleName = new
String(fullyQualifiedName.substring(fullQualifiedName.lastIndexOf('.')));
Eclipse3.1發布以后,使用者發現,3.1占據了大量的Heap(大約200-300M)。Eclipse的開發小組正在不斷地解決這個問題,而String#substing的改進,將在Eclipse 3.1M6中發布(4月1日)。
這個提示,其實也可以運用在我們自己的項目之中
[Note: This blog was migrated from my old CSDN blog.]
為什么重發這個blog呢?因為昨天看到Eclipse.org網站上關于Eclipse Performance的一個文檔。這份文檔主要是提示,在開發基于Eclipse的應用時(不管是Eclipse程序本身,還是Plug-in),在性能問題上需要注意的一些地方。其中,第一條就是如何使用substring()的問題。Eclipse 3.1M7以及RC1,都已經進行了這方面的調整,所以現在的Eclipse,對Heap的占用已經大幅減少,從而在性能上也有所提高。

Eclipse.org
eclipsepowered.org
Email this store to a friend (send a short email with a subject to this story)
Subscribe to kukooBlog (subscribe kukooBlog's RSS feed)
Send me feedback on this story
Eclipse,Java
Eclipse,Programming