Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android GC机制实践调研 #4

Open
qqiabc521 opened this issue Apr 16, 2018 · 0 comments
Open

Android GC机制实践调研 #4

qqiabc521 opened this issue Apr 16, 2018 · 0 comments

Comments

@qqiabc521
Copy link
Owner

qqiabc521 commented Apr 16, 2018

  1. 不同系统不同型号的手机的GC机制是不同的
  2. System.gc()调用结果不同(立即GC或无反应)
  3. 废弃内存回收频率不同
  4. 大规模GC临界值不同
  5. 对于加载图片来说,内存增加量是远大于图片大小的。
  6. 临时变量的GC时机是完全不能保证的,我们可以理解为,GC线程还没有转到这个地方。
  7. System.gc()并不是立刻执行GC的。
  8. 每点击一次按钮,内存消耗增加0.02MB,世界上没有免费的午餐,点击事件内部是会有新的对象产生的
  9. 有时,内存占用只有达到一定限度时,GC才会开始被触发。
  10. 一个空白Activity的内存占用量是0.4MB,返回后再次进入每次增加0.15MB左右,返回键每次增加0~0.01MB左右
  11. 无论Activity是否占用大量内存,其销毁的时间都是迟钝的。
  12. 类成员置NULL,对防止内存溢出崩溃是有必要的
  13. 无论对象大小,都应避免在循环内创建对象
  14. 注意软引用与弱引用的正确使用(弱引用比软引用更容易被销毁,内存抖动更大)

最后告诫一点:尽量不要在应用中调用System.gc(); 如果调用了System.gc()可能会为系统性能带来严重的波动,即便调用System.gc()系统也未必立即响应去执行垃圾回收。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant