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 に答える