0
線路「new String()」導致GC_CONCURRENT語句?
strPuffer = new String(buffer, 0, bytes, Charset.forName("UTF-8"));
的原因有很多GC_CONCURRENT的...
while (true) {
try {
// Read from the InputStream
bytes = mmInStream.read(buffer);
strPuffer = new String(buffer, 0, bytes, Charset.forName("UTF-8"));
curMsg.append(strPuffer);
int endIdx = curMsg.indexOf(end);
if (endIdx != -1) {
fullMessage = curMsg.substring(0, endIdx + end.length()-1);
curMsg.delete(0, endIdx + end.length());
// Send the obtained bytes to the UI Activity
mHandler.obtainMessage(BluetoothChat.MESSAGE_READ, bytes, -1, fullMessage)
.sendToTarget();}
} catch (IOException e) {
//
connectionLost();
break;
}
}
我如何阻止呢?
爲什麼,你的問題是什麼? – 2012-04-06 20:16:04
是不是一個好的跡象,你的垃圾收集器工作正常? :) – waqaslam 2012-04-06 20:20:44
如果你對GC消息不利,你總是可以使用ByteBuffer和CharsetDecoder來做同樣的事情(在更多* loc *中)作爲'new String(..)'。 – Jens 2012-04-06 20:25:19