我的应用程序有一个带有线程的服务,它在后台运行并监听来自远程服务器的通信。当线程运行时,我在我的 LogCat 中看到了很多 dalvikvm 操作。可以吗?或者可能是某种内存泄漏:
这是我的线程运行():
@Override
public void run() {
startKeepAliveTimer();
try {
socket = new Socket(host, port);
if (socket != null)
{
Log.i("ServerConnection", "Server connection opened");
this.app.setConnectedToServer(true);
serverManager.loginToServer();
}
else
app.setConnectedToServer(false);
while (app.isConnectedToServer())
{
app.getFacebookManager().refreshAccessToken();
BufferedReader in = new BufferedReader(new InputStreamReader(
socket.getInputStream()));
String input;
input = in.readLine();
if (input != null)
{
lastOnline = System.currentTimeMillis();
input = input.trim();
input = app.decrypt(input);
Log.e("Server Reponse", input);
serverManager.processData(app.convertToJSONObject(input));
}
}
} catch (IOException e) {
Log.e("ServerConnection", e.toString());
}
Log.i("ServerConnection", "Server connection closed");
}
这是我的堆栈跟踪:
paused 8ms
11-09 15:42:36.862: D/dalvikvm(3806): GC_CONCURRENT freed 1367K, 33% free 10661K/15815K, paused 1ms+2ms
11-09 15:42:36.892: D/dalvikvm(3806): GC_CONCURRENT freed 1390K, 33% free 10661K/15815K, paused 1ms+1ms
11-09 15:42:36.902: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 9ms
11-09 15:42:36.932: D/dalvikvm(3806): GC_CONCURRENT freed 1366K, 33% free 10661K/15815K, paused 1ms+1ms
11-09 15:42:36.952: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 8ms
11-09 15:42:36.972: D/dalvikvm(3806): GC_CONCURRENT freed 1269K, 33% free 10652K/15815K, paused 1ms+1ms
11-09 15:42:36.992: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 12ms
11-09 15:42:37.022: D/dalvikvm(3806): GC_CONCURRENT freed 1269K, 33% free 10652K/15815K, paused 2ms+1ms
11-09 15:42:37.032: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 8ms
11-09 15:42:37.052: D/dalvikvm(3806): GC_CONCURRENT freed 8K, 33% free 10644K/15815K, paused 1ms+1ms
11-09 15:42:37.072: D/dalvikvm(3806): GC_FOR_ALLOC freed 1406K, 33% free 10629K/15815K, paused 9ms
11-09 15:42:37.092: D/dalvikvm(3806): GC_CONCURRENT freed 1245K, 33% free 10652K/15815K, paused 1ms+0ms
11-09 15:42:37.112: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 8ms
11-09 15:42:37.132: D/dalvikvm(3806): GC_CONCURRENT freed 8K, 33% free 10644K/15815K, paused 1ms+1ms
11-09 15:42:37.152: D/dalvikvm(3806): GC_FOR_ALLOC freed 1406K, 33% free 10629K/15815K, paused 9ms
11-09 15:42:37.182: D/dalvikvm(3806): GC_CONCURRENT freed 1245K, 25% free 12018K/15815K, paused 1ms+1ms
11-09 15:42:37.212: D/dalvikvm(3806): GC_CONCURRENT freed 3208K, 33% free 10664K/15815K, paused 1ms+0ms
11-09 15:42:37.232: D/dalvikvm(3806): GC_FOR_ALLOC freed 1426K, 33% free 10637K/15815K, paused 11ms
11-09 15:42:37.252: D/dalvikvm(3806): GC_CONCURRENT freed 1269K, 33% free 10652K/15815K, paused 1ms+0ms
11-09 15:42:37.272: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 9ms
11-09 15:42:37.302: D/dalvikvm(3806): GC_CONCURRENT freed 1366K, 33% free 10661K/15815K, paused 3ms+0ms
11-09 15:42:37.312: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 9ms
11-09 15:42:37.332: D/dalvikvm(3806): GC_CONCURRENT freed 1269K, 33% free 10652K/15815K, paused 1ms+0ms
11-09 15:42:37.362: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 7ms
11-09 15:42:37.402: D/dalvikvm(3806): GC_CONCURRENT freed 1360K, 33% free 10667K/15815K, paused 1ms+1ms
11-09 15:42:37.432: D/dalvikvm(3806): GC_CONCURRENT freed 1299K, 33% free 10652K/15815K, paused 1ms+1ms
11-09 15:42:37.452: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 13ms
11-09 15:42:37.472: D/dalvikvm(3806): GC_CONCURRENT freed 1269K, 33% free 10652K/15815K, paused 1ms+1ms
11-09 15:42:37.492: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 12ms
11-09 15:42:37.512: D/dalvikvm(3806): GC_CONCURRENT freed 1366K, 33% free 10661K/15815K, paused 1ms+0ms
11-09 15:42:37.532: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 8ms
11-09 15:42:37.552: D/dalvikvm(3806): GC_CONCURRENT freed 1269K, 33% free 10652K/15815K, paused 1ms+1ms
11-09 15:42:37.572: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 8ms
11-09 15:42:37.622: D/dalvikvm(3806): GC_CONCURRENT freed 1266K, 32% free 10761K/15815K, paused 1ms+1ms
11-09 15:42:37.642: D/dalvikvm(3806): GC_FOR_ALLOC freed 1562K, 33% free 10629K/15815K, paused 13ms
11-09 15:42:37.672: D/dalvikvm(3806): GC_CONCURRENT freed 1367K, 33% free 10653K/15815K, paused 1ms+1ms
11-09 15:42:37.692: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 10ms
11-09 15:42:37.712: D/dalvikvm(3806): GC_CONCURRENT freed 1366K, 33% free 10661K/15815K, paused 1ms+1ms
11-09 15:42:37.722: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 8ms
11-09 15:42:37.752: D/dalvikvm(3806): GC_CONCURRENT freed 1269K, 32% free 10758K/15815K, paused 2ms+1ms
11-09 15:42:37.762: D/dalvikvm(3806): GC_FOR_ALLOC freed 1559K, 33% free 10629K/15815K, paused 11ms
11-09 15:42:37.792: D/dalvikvm(3806): GC_CONCURRENT freed 1367K, 33% free 10653K/15815K, paused 2ms+1ms
11-09 15:42:37.812: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 10ms
11-09 15:42:37.832: D/dalvikvm(3806): GC_CONCURRENT freed 1269K, 33% free 10652K/15815K, paused 1ms+1ms
11-09 15:42:37.852: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 10ms
11-09 15:42:37.872: D/dalvikvm(3806): GC_CONCURRENT freed 8K, 33% free 10644K/15815K, paused 1ms+1ms
11-09 15:42:37.882: D/dalvikvm(3806): GC_FOR_ALLOC freed 1406K, 33% free 10629K/15815K, paused 9ms
11-09 15:42:37.912: D/dalvikvm(3806): GC_CONCURRENT freed 1245K, 33% free 10652K/15815K, paused 1ms+0ms
11-09 15:42:37.932: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 8ms
11-09 15:42:37.962: D/dalvikvm(3806): GC_CONCURRENT freed 1366K, 33% free 10661K/15815K, paused 0ms+1ms
11-09 15:42:37.972: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 10ms
11-09 15:42:38.002: D/dalvikvm(3806): GC_CONCURRENT freed 1269K, 32% free 10758K/15815K, paused 1ms+1ms
11-09 15:42:38.012: D/dalvikvm(3806): GC_FOR_ALLOC freed 1559K, 33% free 10629K/15815K, paused 12ms
11-09 15:42:38.042: D/dalvikvm(3806): GC_CONCURRENT freed 1367K, 33% free 10653K/15815K, paused 1ms+1ms
11-09 15:42:38.062: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 8ms
11-09 15:42:38.092: D/dalvikvm(3806): GC_CONCURRENT freed 1366K, 33% free 10661K/15815K, paused 1ms+1ms
11-09 15:42:38.112: D/dalvikvm(3806): GC_CONCURRENT freed 1293K, 33% free 10652K/15815K, paused 1ms+0ms
11-09 15:42:38.132: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 13ms
11-09 15:42:38.162: D/dalvikvm(3806): GC_CONCURRENT freed 1269K, 33% free 10652K/15815K, paused 2ms+1ms
11-09 15:42:38.182: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 11ms
11-09 15:42:38.202: D/dalvikvm(3806): GC_CONCURRENT freed 1269K, 33% free 10652K/15815K, paused 1ms+0ms
11-09 15:42:38.222: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 8ms
11-09 15:42:38.242: D/dalvikvm(3806): GC_CONCURRENT freed 1269K, 33% free 10652K/15815K, paused 1ms+1ms
11-09 15:42:38.262: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 7ms
11-09 15:42:38.272: D/dalvikvm(3806): GC_CONCURRENT freed 8K, 33% free 10644K/15815K, paused 1ms+1ms
11-09 15:42:38.292: D/dalvikvm(3806): GC_FOR_ALLOC freed 1406K, 33% free 10629K/15815K, paused 8ms
11-09 15:42:38.322: D/dalvikvm(3806): GC_CONCURRENT freed 1366K, 33% free 10653K/15815K, paused 1ms+1ms
11-09 15:42:38.342: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 7ms
11-09 15:42:38.362: D/dalvikvm(3806): GC_CONCURRENT freed 1269K, 33% free 10652K/15815K, paused 1ms+1ms
11-09 15:42:38.382: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 8ms
11-09 15:42:38.402: D/dalvikvm(3806): GC_CONCURRENT freed 8K, 33% free 10644K/15815K, paused 1ms+0ms
11-09 15:42:38.412: D/dalvikvm(3806): GC_FOR_ALLOC freed 1406K, 33% free 10629K/15815K, paused 9ms
11-09 15:42:38.442: D/dalvikvm(3806): GC_CONCURRENT freed 1245K, 33% free 10652K/15815K, paused 1ms+1ms
11-09 15:42:38.462: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 9ms
11-09 15:42:38.492: D/dalvikvm(3806): GC_CONCURRENT freed 8K, 25% free 12019K/15815K, paused 1ms+2ms
11-09 15:42:38.522: D/dalvikvm(3806): GC_CONCURRENT freed 3103K, 32% free 10769K/15815K, paused 1ms+2ms
11-09 15:42:38.532: D/dalvikvm(3806): GC_FOR_ALLOC freed 1570K, 33% free 10637K/15815K, paused 9ms
11-09 15:42:38.552: D/dalvikvm(3806): GC_CONCURRENT freed 1270K, 33% free 10652K/15815K, paused 1ms+1ms
11-09 15:42:38.572: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 7ms
11-09 15:42:38.592: D/dalvikvm(3806): GC_CONCURRENT freed 1366K, 33% free 10661K/15815K, paused 1ms+1ms
11-09 15:42:38.622: D/dalvikvm(3806): GC_CONCURRENT freed 1293K, 32% free 10758K/15815K, paused 1ms+1ms
11-09 15:42:38.632: D/dalvikvm(3806): GC_FOR_ALLOC freed 1559K, 33% free 10629K/15815K, paused 11ms
11-09 15:42:38.662: D/dalvikvm(3806): GC_CONCURRENT freed 1246K, 33% free 10652K/15815K, paused 1ms+1ms
11-09 15:42:38.682: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 13ms
11-09 15:42:38.702: D/dalvikvm(3806): GC_CONCURRENT freed 1269K, 33% free 10652K/15815K, paused 1ms+1ms
11-09 15:42:38.722: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 11ms
11-09 15:42:38.742: D/dalvikvm(3806): GC_CONCURRENT freed 1269K, 33% free 10652K/15815K, paused 1ms+1ms
11-09 15:42:38.762: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 10ms
11-09 15:42:38.782: D/dalvikvm(3806): GC_CONCURRENT freed 8K, 33% free 10644K/15815K, paused 1ms+1ms
11-09 15:42:38.802: D/dalvikvm(3806): GC_FOR_ALLOC freed 1406K, 33% free 10629K/15815K, paused 10ms
11-09 15:42:38.822: D/dalvikvm(3806): GC_CONCURRENT freed 1245K, 33% free 10652K/15815K, paused 1ms+1ms
11-09 15:42:38.842: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 9ms
11-09 15:42:38.872: D/dalvikvm(3806): GC_CONCURRENT freed 1269K, 24% free 12027K/15815K, paused 1ms+1ms
11-09 15:42:38.902: D/dalvikvm(3806): GC_CONCURRENT freed 3208K, 33% free 10672K/15815K, paused 1ms+0ms
11-09 15:42:38.912: D/dalvikvm(3806): GC_FOR_ALLOC freed 1450K, 33% free 10629K/15815K, paused 9ms
11-09 15:42:38.942: D/dalvikvm(3806): GC_CONCURRENT freed 1366K, 33% free 10653K/15815K, paused 1ms+1ms
11-09 15:42:38.962: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 7ms
11-09 15:42:38.982: D/dalvikvm(3806): GC_CONCURRENT freed 1269K, 33% free 10652K/15815K, paused 1ms+1ms
11-09 15:42:39.002: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 10ms
11-09 15:42:39.022: D/dalvikvm(3806): GC_CONCURRENT freed 1269K, 33% free 10652K/15815K, paused 1ms+1ms
11-09 15:42:39.042: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 8ms
11-09 15:42:39.072: D/dalvikvm(3806): GC_CONCURRENT freed 1366K, 33% free 10661K/15815K, paused 1ms+1ms
11-09 15:42:39.092: D/dalvikvm(3806): GC_CONCURRENT freed 1390K, 33% free 10661K/15815K, paused 1ms+1ms
11-09 15:42:39.112: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 9ms
11-09 15:42:39.132: D/dalvikvm(3806): GC_CONCURRENT freed 1366K, 33% free 10661K/15815K, paused 1ms+1ms
11-09 15:42:39.152: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 8ms
11-09 15:42:39.172: D/dalvikvm(3806): GC_CONCURRENT freed 1269K, 33% free 10652K/15815K, paused 1ms+0ms
11-09 15:42:39.192: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 11ms
11-09 15:42:39.212: D/dalvikvm(3806): GC_CONCURRENT freed 1269K, 33% free 10652K/15815K, paused 1ms+1ms
11-09 15:42:39.232: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 9ms
11-09 15:42:39.252: D/dalvikvm(3806): GC_CONCURRENT freed 1269K, 33% free 10652K/15815K, paused 1ms+1ms
11-09 15:42:39.272: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 10ms
11-09 15:42:39.302: D/dalvikvm(3806): GC_CONCURRENT freed 1269K, 33% free 10652K/15815K, paused 2ms+1ms
11-09 15:42:39.322: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 11ms
11-09 15:42:39.342: D/dalvikvm(3806): GC_CONCURRENT freed 1366K, 33% free 10661K/15815K, paused 2ms+1ms
11-09 15:42:39.362: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 11ms
11-09 15:42:39.382: D/dalvikvm(3806): GC_CONCURRENT freed 1269K, 33% free 10652K/15815K, paused 1ms+1ms
11-09 15:42:39.402: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 11ms
11-09 15:42:39.432: D/dalvikvm(3806): GC_CONCURRENT freed 1269K, 32% free 10758K/15815K, paused 1ms+1ms
11-09 15:42:39.442: D/dalvikvm(3806): GC_FOR_ALLOC freed 1559K, 33% free 10629K/15815K, paused 11ms
11-09 15:42:39.472: D/dalvikvm(3806): GC_CONCURRENT freed 1246K, 33% free 10652K/15815K, paused 1ms+1ms
11-09 15:42:39.492: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 10ms
11-09 15:42:39.522: D/dalvikvm(3806): GC_CONCURRENT freed 1269K, 33% free 10652K/15815K, paused 1ms+1ms
11-09 15:42:39.532: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 8ms
11-09 15:42:39.562: D/dalvikvm(3806): GC_CONCURRENT freed 1269K, 33% free 10652K/15815K, paused 2ms+1ms
11-09 15:42:39.572: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 9ms
11-09 15:42:39.602: D/dalvikvm(3806): GC_CONCURRENT freed 1269K, 33% free 10652K/15815K, paused 1ms+1ms
11-09 15:42:39.612: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 12ms
11-09 15:42:39.642: D/dalvikvm(3806): GC_CONCURRENT freed 1269K, 33% free 10652K/15815K, paused 1ms+1ms
11-09 15:42:39.652: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 9ms
11-09 15:42:39.682: D/dalvikvm(3806): GC_CONCURRENT freed 1269K, 32% free 10758K/15815K, paused 1ms+2ms
11-09 15:42:39.692: D/dalvikvm(3806): GC_FOR_ALLOC freed 1559K, 33% free 10629K/15815K, paused 10ms
11-09 15:42:39.722: D/dalvikvm(3806): GC_CONCURRENT freed 1246K, 33% free 10652K/15815K, paused 1ms+1ms
11-09 15:42:39.742: D/dalvikvm(3806): GC_FOR_ALLOC freed 1414K, 33% free 10637K/15815K, paused 12ms
11-09 15:42:39.762: D/dalvikvm(3806): GC_CONCURRENT freed 1366K, 33% free 10661K/15815K, paused 1ms+1ms
更新: 从循环内部删除所有“新”元素后,我使用了 DDMS 分配跟踪器,发现我在 input=in.readLine(); 中有很多分配;InputStream 对象中带有 wrap() 函数的东西……怎么可能?以及该怎么做