Best practices
Now that we know what can happen in memory while our application is active, let's examine what we can do to avoid memory leaks and memory churns and optimize our memory management in order to reach our performance target, not just in memory usage, but in garbage collection attendance, because, as we know, it stops any other operation from working.
In the following pages, we will go through a lot of hints and tips using a bottom-up strategy: starting from low-level shrewdness in Java code to highest-level Android practices.
Data types
We weren't joking: we are really talking about Java primitive types, as they are the foundation of all the applications and it's really important to know how to deal with them, even though it may be obvious. It's not, and we will soon understand why.
Java provides primitive types that need to be saved in memory when used: the system allocates an amount of memory related to the amount requested for that particular type. The following...