How do i stop the android garbage collector? Is it possible?

前端 未结 2 1968
感情败类
感情败类 2021-01-17 19:47

Is there any way to stop the garbage collector for some time?

相关标签:
2条回答
  • 2021-01-17 20:03

    I guess you are willing to avoid getting lagged by the gc. If this is the case, your question is similar to this one.

    Basically you can't stop the gc but you can force a call using System.gc().

    0 讨论(0)
  • 2021-01-17 20:06

    The best way of not be lagged by the GC is to avoid the need to collect garbage all the time. You could for example reuse objects instead of nulling them and creating new ones. This quite same pattern as androids CursorAdapter is doing when reusing the View's, it just reused a view to represent new data. The drawback of this that you have to do it manually and program in a very precise way. Also you'll get a better memory handling and a performance boost.

    0 讨论(0)
提交回复
热议问题