Potential problems with static statics static variables:
1. Memory is occupied and memory is not normally released;
2. Static memory is automatically reclaimed when the system is not in memory, which can cause access to global static errors.
3. The activity cannot be used as a static statically object, so that all component objects of the activity are stored in global memory and are not recycled;
(Transferred from: http://blog.csdn.net/ctcwri/article/details/8858414)
The life cycle of a static variable:
When is the class loaded?
When we launch an app, the system creates a process that loads an instance of the Dalvik VM, then the code runs on the DVM, the load and unload of classes, garbage collection, and so on are the responsibility of the DVM. This means that when the process starts, the class is loaded and the static variable is allocated memory.
Static variables are destroyed when the class is unloaded.
When was the class unloaded?
At the end of the process.
Note: In general, all classes are default ClassLoader loaded, as long as ClassLoader exist, the class will not be unloaded, and the default ClassLoader life cycle is consistent with the process, this article discusses the general situation.
Iii. when the process of Android is over
This is Android's process and memory management is different from the core of the PC-if the resources are sufficient, Android will not kill any process, another means that the process can be killed at any time . Android will restart the process of being killed when resources are sufficient. That is, the value of a static variable, if not done, is unreliable, it can be said that everything in memory is unreliable. If you want to be reliable, you still have to save it to the NAND or SD card and restore it back when you reboot.
Another scenario is that you cannot leave all activity equal to the exit of the process, so when the user clicks on the icon to launch the application, the value that was previously stored in the static variable may still exist , so it is necessary to give the empty operation depending on the situation.
Four, application is equally unreliable
Application is actually a singleton object, also put in memory, when the process is killed, it is completely emptied, but the Android system will help rebuild the application, and we stored in the application data naturally no, or have to deal with their own.
V. Objects that are statically referenced are not garbage collected
As long as the static variable is not destroyed and there is no null, its object has been kept referenced, that is, the reference count cannot be 0, and therefore is not garbage collected. Therefore, singleton objects are not recycled at run time.
Extension: http://blog.csdn.net/u010192087/article/details/41206251
Android try not to use static variables