`
kei502
  • 浏览: 2491 次
  • 性别: Icon_minigender_1
  • 来自: 厦门
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

何时调用system.gc()

阅读更多
Nokia 的文档Known Issues In The Nokia 6600 MIDP 2.0 Implementation v1.7说:
2.15.1 Garbage collecting
Description
Calling the System.gc() method results in extreme slowness and jamming. In Monty 1.0 VM, garbage
collection is different and every time System.gc is called, the entire memory is really cleared.
This is an extremely slow process!
Solution
Do not call the System.gc method at all, or call the System.gc() garbage collecting method only
in non-time-critical situations, such as screen transitions, state transitions, pause states,
etc. If the System.gc() method is used, it is recommended to add a short delay (~20-50 ms) after
the method call to ensure the sufficient time for the garbage collection, as in the following

example
System.gc();
Thread.sleep(delay);
delay = 20-50 ms

调用 System.gc()将会真正的清除内存条目,而这是一个极慢的过程。
解决:1.不调用 System.gc()
2.在屏幕切换,状态转换,暂停状态等情况下调用,并且在调用 System.gc() 时加上个短暂的延时
如:
System.gc();
Thread.sleep(delay);
delay = 20-50 ms
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics