在Android中,不应该使用System.gc()吗? [英] In Android, Should not be use System.gc()?

查看:67
本文介绍了在Android中,不应该使用System.gc()吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道不应该在Android中使用System.gc().

I wonder should not be use System.gc() in android.

我搜索了开发者文档:

结果:

public static void gc()

public static void gc ()

已在API级别1中添加,向VM指示是个好时机运行垃圾收集器.请注意,这仅是一个提示.有无法保证垃圾收集器会真正运行.

Added in API level 1 Indicates to the VM that it would be a good time to run the garbage collector. Note that this is a hint only. There is no guarantee that the garbage collector will actually be run.

,然后找到参考信息.这个网址: http://code.google.com/p/android/issues/detail?id = 8488#c80

and, find reference infomation. this url : http://code.google.com/p/android/issues/detail?id=8488#c80

但这是很久以前了.

如果使用Bitmap,请使用bitmap.recycle().但意见复杂,如何进行gc?

if use Bitmap, use bitmap.recycle(). but complex views, how to gc?

现在,这个问题没有解决吗?从未使用过System.gc()?

Now, is that problem not resolved? and never used System.gc()?

推荐答案

调用 System.gc()并不能保证实际执行垃圾收集.它比其他任何东西都更有暗示性.

Invoking System.gc() is not a guarantee of garbage collection actually being performed. It's more of a hint than anything else.

通常,在Java编程中,使用此方法调用被认为是非常糟糕的做法,因为使用此方法意味着一定程度的期望发生垃圾回收.实际上,何时进行垃圾回收取决于很多事情,最好留给容器和运行时调整(如果需要).

In Java programming in general it has been regarded as very bad practice to use this method call because using it implies some level of expectation that garbage collection then happens. In truth, when garbage collection occurs depends on many things and is best left to the container and run-time tuning (if required).

出于同样的原因,我会说不要在Android中使用 System.gc().

I'd say don't use System.gc() in Android for all the same reasons.

这篇关于在Android中,不应该使用System.gc()吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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