1. BlackBerry Object Handler要够用
程序不能消耗太多的对象句柄
2. 还是BlackBerry Object Handler,在Persistant Store的persistent object handles也是有限的,要节约使用
参考:Performance of the persistent store
(BlackBerry Manuals & Help > Documentation for Developers >Java Development Guides and API Reference> Data Storage - Development Guide - BlackBerry Java SDK - 7.0 >Performance of the persistent store)
5.TCP网络服务器返回数据给BlackBerry的最后要做flush动作,否则BlackBerry会等待超时,耗费很多时间
6.System.gc() 垃圾回收
参考1:displaying System busy icon
大意是说如果发现黑莓手机运行你的程序出现漏斗,估计是你的程序产生内存垃圾,内存碎片等,需要黑莓手机操作系统对内存进行整理。
而黑莓的内存整理是非常耗时的。
注意参考1中的日志细节:
VM:+GC(F)w=6
表明BlackBerry OS在做GC垃圾回收。
注意事项:
Looks like you are creating excess garbage. The system GC will kick in when memory becomes constrained, whether you called it or not.
Some things to look for:
* string concantenation, expecially within a for...next loop.
* unnec. use of Enumerations
* keeping references to objects that are no longer needed (set them to null)
There is a heirarchy to garbage collection on the BB. It goes something like this:
#1 - RAM collection of unused objects: < ~500 ms
#2 - Collection of unused objects in object cache (flash): ~1,000 ms, then repeat #1
#3 - Collection of unsued objects in store: ~2,000 ms, then repeat #2
参考2:BlackBerry: Taking Out the Trash: Garbage Collection (>Developers _>Resources>Developer Journals>January 2005)
参考3:BlackBerry J2ME calling system.gc()
7: 谷歌搜索:blackberry Best Practices site:docs.blackberry.com
Best practice: Writing efficient code (5.0)
Best practice: Writing efficient code(4.6)
8. 一般性的Java内存使用问题
字符串使用,不再使用的对象句置null,尽量重用对象而不是反复生成并丢弃大量的小对象。
9. J2ME性能优化:移动网络环境下ReadBuffer的使用
by keyboardota
10. J2ME性能优化:程序开发要注意函数调用对性能的影响
刚开始,我一直集中精力在改进处理逻辑上,尽量减少处理路径,但这种做法收到的效果很不明显,基本上可以忽略不计;我也明白调用函数会引起效率的降低,但我一直以为这个损失的效率应该是很低的,也可以忽略不计,所以就没有过多的关注,直到有一天跟部门经理讨论时,他让我试把YUV to RGB的代码的函数调用都写在一起,没想到经过这么一改,性能提高不少,从原来每一帧的YUV to RGB需要耗时200多ms降为50多ms,让我大吃一惊。
因此,在J2ME开发中,如果在一些实时性要求很强的模块,尽量避免函数的调用,可以牺牲代码的可读性来换取更短的运行时间。
参考资料:
How to find that memory leak! (PartOne)
How To Find That Memory Leak (Part Two): Detecting TheLeak
How To Find That Memory Leak (Part Three): Why An Object is Leaking IntoMemory
最后更新:2011.12.29