先说命令,详细讲解放在后面
查看内存使用情况
- adb shell dumpsys meminfo [pkg] 查看指定进程包名的内存使用情况
命令详解
android程序内存被分为2部分:native和dalvik,dalvik就是java堆,普通java对象是在java堆分配,而bitmap是直接在native上分配,对于内存的限制是 native+dalvik 不能超过最大限制。android程序内存一般限制在16M,当然也有24M的。
pplications Memory Usage (kB): Uptime: 27199950 Realtime: 145023102 ** MEMINFO in pid 20100 [com.laomou.memtest] ** Pss Private Private Swapped Heap Heap Heap Total Dirty Clean Dirty Size Alloc Free ------ ------ ------ ------ ------ ------ ------ Native Heap 1876 1544 0 15964 29440 27821 1618 Dalvik Heap 780 740 0 36 17032 15133 1899 Dalvik Other 496 312 0 8500 Stack 136 136 0 4 Other dev 4 0 4 0 .so mmap 457 56 164 2696 .apk mmap 127 0 20 0 .dex mmap 386 44 340 4 .oat mmap 1070 0 340 0 .art mmap 1520 388 544 140 Other mmap 11 8 0 0 Unknown 92 92 0 116 TOTAL 6955 3320 1412 27460 46472 42954 3517 App Summary Pss(KB) ------ Java Heap: 1672 Native Heap: 1544 Code: 964 Stack: 136 Graphics: 0 Private Other: 416 System: 2223 TOTAL: 6955 TOTAL SWAP (KB): 27460 Objects Views: 7 ViewRootImpl: 0 AppContexts: 2 Activities: 1 Assets: 4 AssetManagers: 2 Local Binders: 3 Proxy Binders: 8 Parcel memory: 2 Parcel count: 10 Death Recipients: 0 OpenSSL Sockets: 0 Dalvik isLargeHeap: false SQL MEMORY_USED: 0 PAGECACHE_OVERFLOW: 0 MALLOC_SIZE: 0
- Objects
查看参数,如果Views、Activities 不等于0的话,那么肯定存在内存泄漏。 - Dalvik
isLargeHeap: false - AndroidManifest.xml
<application android:largeHeap="false">
如果不是内存消耗大的应用,如图库之类,建议不要设置isLargeHeap=true