Monday, February 25, 2008

Code Optimization - Java ME

Code Optimization - Java ME

Since mobile phones have low heap memory, restrictions on jar sizes supported, and slow CPU's, optimizations can be employed to improve your applications performance. Consider your usage of memory, application size, and CPU overhead.

Here is a compilation of code optimization techniques which may be quite helpful to reduce jar size and memory usage.

1. Use an obfuscator like the free Proguard or Retroguard. They can remove unused code and perform other optimizations to decrease MIDlet size (JAR file size).
2. Use minimum number of classes, even a mostly-empty class uses space.
3. Avoid unnecessary object creation.
4. Reuse objects when possible.
5. For saving memory, explicitly set unused object to null.
6. Beware of calling garbage collection, calling system.gc to free memory may cause slowdowns because in certain phones it is a blocking statement.
7. Use only minimum images in the application to save space.
8. If not using an obfuscator
1. All the variable, method & class name should be small
2. Remove any unwanted code
3. The package structure should be as minimum as possible, if possible avoid packages


No comments: