在Android的垃圾收集器 [英] Garbage collector in Android

查看:129
本文介绍了在Android的垃圾收集器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到提示要求在某些情况下,垃圾收集众多A​​ndroid答案。

I have seen many Android answers that suggest calling the garbage collector in some situations.

它是一个很好的做法做了占用内存运行之前请求在Android上的垃圾收集器?如果不是这样,我应该只调用它,如果我得到一个内存不足错误?

Is it a good practice to request the garbage collector in Android before doing a memory-hungry operation? If not, should I only call it if I get an OutOfMemory error?

是我诉诸垃圾收集器?

推荐答案

做电的System.gc()

我试图创建位图,但总是出现虚拟内存不足的错误。但是,当我叫的System.gc()第一,它是确定。

I tried to create Bitmaps, but was always getting "VM out of memory error". But, when I called System.gc() first, it was OK.

在创建位图,机器人经常失败,内存不足的错误,而不尝试垃圾回收第一的。因此,调用的System.gc(),和你有足够的内存来创建位图。

When creating bitmaps, Android often fails with out of memory errors, and does not try to garbage collect first. Hence, call System.gc(), and you have enough memory to create Bitmaps.

如果创建对象,我觉得的System.gc 将被自动如果需要调用, 但是的没有的用于创建位图。它只是失败。

If creating Objects, I think System.gc will be called automatically if needed, but not for creating bitmaps. It just fails.

所以,我建议您手动调用的System.gc()创建位图前。

So I recommend manually calling System.gc() before creating bitmaps.

这篇关于在Android的垃圾收集器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆