安卓开发-内存使用分析

来源:互联网 发布:php 魔术方法 编辑:程序博客网 时间:2024/06/05 06:07

VSS - Virtual Set Size 虚拟耗用内存(包含共享库占用的内存)

RSS - Resident Set Size 实际使用物理内存(包含共享库占用的内存)

PSS - Proportional Set Size 实际使用的物理内存(比例分配共享库占用的内存)

USS - Unique Set Size 进程独自占用的物理内存(不包含共享库占用的内存)

一般来说内存占用大小有如下规律:VSS >= RSS >= PSS >= USS



内存优化点:

1、String的intern

经过intern的String在java1.6还是被放在perm gen的。这样能够优化String对象的使用(防止相同的字符串在堆上占用多份内存)。但是过多的intern会导致永久存储区越来越大(可能会导致永久存储区溢出)。而且,经过intern的String,如果开发者能够保证自己使用的就是intern的字符串的话,那么他们就可以使用== 来判等了。这篇文章作者做过测试,==比equals快5倍左右。

------------------------------------------

 Internalized strings are released if they are no longer referenced.

intern过的String如果没有被reference,也是会被垃圾回收的。

------------------------------------------

一种好的方法,既可以缓存String对象,让你所用的STring对象在内存中只有一份,而且还不占用永久存储区,可以自己使用hashmap来做。看看这篇。

---------------------------------------------

但是,如果使用的是java1.7,那么intern的String是存储在堆上的。就不用管永久存储区溢出的问题了。看下面:

If you are running Java 7, internalized Strings are stored in the heap (assuming you are using the HotSpot JVM). So that removes the problem of running out of PermGen space.

--------------------------------------













http://android-developers.blogspot.com/2011/03/memory-analysis-for-android.html