This is an open question towards learning about memory optimization and code optimization for faster execution. What would you give more importance within the two ?
How do you usually optimize you code to use memory efficiently ?
How do you optimize your code to run faster ?
As a mobile developer we’ve to give importance to use memory properly. But sometimes using it usually backfires by creating more objects or under utilizing the memory.
What are your usual methods to optimize memory & decrease the run time of the application ?
This is a difficult to answer question. There is no general answer to this question, it depends on your priorities. For some apps(chess programs) it is the efficiency, for some apps(gallery app) it is the memory usage that is more important. However, more often than not, neither of these could be a bottleneck. In such cases, you should choose the cleanest and easiest to maintain way.
However in my experience, most of the time it is the memory that cause the bottleneck(if there is one at all) on Android. On
StackOverflow, everyday I see some posts aboutOutOfMemoryerrors and I rarely see amy app is running too slowpost.Here are some specific tips that come to my mind:
1) Call
whenever the
bitmapis not needed. This could release the memory earlier.2)
Try to avoid file access as much as possible. Using a SQLite db can help you achieve that in a more efficient way.
3)
Don’t leak memory. Use memory management tools that come with eclipse to track those leaks.
4)
Hand big files in chunks, and small files without chunks!
5)
Check this video on "android memory management". It gives plenty of useful information.
Also there is similar discussion here: Memory efficiency vs Processor efficiency (note that it is not specifically for android)