我正在测试一个只有一个Hello world活动的简单Android应用程序:
public class MyActivity extends Activity {
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
long total = Runtime.getRuntime().totalMemory();
long free = Runtime.getRuntime().freeMemory();
Log.d("TEST MEM LEAK ", "max:" + Runtime.getRuntime().maxMemory() / 1024 + "K, total:" + total / 1024 + "K, free:" + free / 1024 + "K");
}
}
这是App第一次打开,我通过以下方式转发了男士信息:
$adb shell dumpsys meminfo com.example.Testmemleak
** MEMINFO in pid 1506 [com.example.Testmemleak] **
native dalvik other total
size: 3212 2819 N/A 6031
allocated: 3200 2377 N/A 5577
free: 11 442 N/A 453
(Pss): 726 856 992 2574
(shared dirty): 1404 4156 1420 6980
(priv dirty): 664 436 628 1728
Objects
Views: 0 ViewRoots: 0
AppContexts: 0 Activities: 0
Assets: 2 AssetManagers: 2
Local Binders: 5 Proxy Binders: 11
Death Recipients: 0
OpenSSL Sockets: 0
SQL
heap: 0 memoryUsed: 0
pageCacheOverflo: 0 largestMemAlloc: 0
这是第二次转储信息:
** MEMINFO in pid 1506 [com.example.Testmemleak] **
native dalvik other total
size: 3320 2819 N/A 6139
allocated: 3268 2438 N/A 5706
free: 51 381 N/A 432
(Pss): 824 994 1082 2900
(shared dirty): 1396 4136 1364 6896
(priv dirty): 760 532 708 2000
Objects
Views: 0 ViewRoots: 0
AppContexts: 0 Activities: 0
Assets: 2 AssetManagers: 2
Local Binders: 7 Proxy Binders: 13
Death Recipients: 1
OpenSSL Sockets: 0
SQL
heap: 0 memoryUsed: 0
pageCacheOverflo: 0 largestMemAlloc: 0
这是我退出后的日志,并按几次BACK和app图标重新进入应用程序:
01-01 13:38:36.669 1506-1506/com.example.Testmemleak D/TEST MEM LEAK﹕ max:32768K, total:2819K, free:469K
01-01 13:39:51.206 1506-1506/com.example.Testmemleak D/TEST MEM LEAK﹕ max:32768K, total:2819K, free:395K
01-01 13:41:16.005 1506-1506/com.example.Testmemleak D/TEST MEM LEAK﹕ max:32768K, total:2819K, free:344K
01-01 13:41:25.486 1506-1506/com.example.Testmemleak D/TEST MEM LEAK﹕ max:32768K, total:2819K, free:326K
01-01 13:51:22.286 1506-1506/com.example.Testmemleak D/TEST MEM LEAK﹕ max:32768K, total:2887K, free:508K
01-01 13:51:25.380 1506-1506/com.example.Testmemleak D/TEST MEM LEAK﹕ max:32768K, total:2887K, free:489K
01-01 13:51:30.819 1506-1506/com.example.Testmemleak D/TEST MEM LEAK﹕ max:32768K, total:2887K, free:470K
01-01 13:51:33.268 1506-1506/com.example.Testmemleak D/TEST MEM LEAK﹕ max:32768K, total:2887K, free:452K
01-01 13:51:36.382 1506-1506/com.example.Testmemleak D/TEST MEM LEAK﹕ max:32768K, total:2887K, free:433K
01-01 13:51:39.007 1506-1506/com.example.Testmemleak D/TEST MEM LEAK﹕ max:32768K, total:2887K, free:415K
01-01 13:51:41.397 1506-1506/com.example.Testmemleak D/TEST MEM LEAK﹕ max:32768K, total:2887K, free:396K
01-01 13:51:43.794 1506-1506/com.example.Testmemleak D/TEST MEM LEAK﹕ max:32768K, total:2887K, free:377K
01-01 13:51:46.143 1506-1506/com.example.Testmemleak D/TEST MEM LEAK﹕ max:32768K, total:2887K, free:359K
01-01 13:51:48.833 1506-1506/com.example.Testmemleak D/TEST MEM LEAK﹕ max:32768K, total:2887K, free:340K
01-01 13:51:50.970 1506-1506/com.example.Testmemleak D/TEST MEM LEAK﹕ max:32768K, total:2887K, free:322K
01-01 13:51:53.143 1506-1506/com.example.Testmemleak D/TEST MEM LEAK﹕ max:32768K, total:2951K, free:367K
01-01 13:51:57.246 1506-1506/com.example.Testmemleak D/TEST MEM LEAK﹕ max:32768K, total:2951K, free:348K
01-01 13:51:59.215 1506-1506/com.example.Testmemleak D/TEST MEM LEAK﹕ max:32768K, total:2951K, free:330K
01-01 13:52:01.396 1506-1506/com.example.Testmemleak D/TEST MEM LEAK﹕ max:32768K, total:3015K, free:375K
01-01 13:52:03.273 1506-1506/com.example.Testmemleak D/TEST MEM LEAK﹕ max:32768K, total:3015K, free:356K
似乎堆大小和代理/本地绑定器在退出后继续增加并进入应用程序,为什么?是默认的“内存泄漏”吗?