0

线

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;
                }

            }

我该如何防止呢?

4

1 回答 1

1

您正在循环中创建很多对象。看到这条消息仅仅意味着垃圾收集器正在通过释放你的内存来完成它的工作。GC 清理堆中未被引用的对象。

于 2012-04-06T20:22:05.107 回答