Android memory release processing
I don't know what kind of processing is done for the release of the android memory. I am not familiar with android. Recently, during the development of small games, I felt better when I first played games because there were many game interface components, however, after entering the game interface for several times, the game will get stuck and I will be speechless in an instant. If I want to get it, I still cannot release the memory usage. After some learning, although the root cause is not found completely, it has been mitigated a lot. Let's talk about how I handle it here. If you have your own good solutions, I hope you can share them with me, so that everyone can make progress together. The following are some of my practices:
First, I know most of the memory usage (I usually release resources in onDestroy ):
1. image resources;
2. list usage;
3. array occupation;
4. Use of other defined methods;
5. Thread callback. The thread is not closed.
In the face of these problems, I use the following methods:
1. Image Resource Recycling
Private void recycleBitmap ()
{
If (viewGroup! = Null)
{
Int count = viewGroup. getChildCount;
For (int I = 0; I {
View view = viewGroup. getChildAt (I );
ImageView img = (ImageView) view. findViewById (R. id. Image );
If (img! = Null)
{
Drawable drawable = img. getDrawable ();
If (drawable! = Null)
{
If (drawable instanceof BitmapDrawable)
{
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
Bitmap bitmap = bitmapDrawable. getBitmap ();
If (bitmap! = Null)
Bitmap. recycle ();
}
}
}
}
}
}
2. list usage:
Method: list. clear (); and then empty in the system. I don't know if this is necessary, but there is only one sentence, and there is no exception, so by the way;
3. array occupation:
Method: empty if it is used up;
4. Usage of other defined methods:
Method: Empty directly. If there are some lists or arrays in the method, my solution is to define another method to release resources in the defined method, call the method to release the internal data of the method when you want to release the resource;
5. Thread callback. The thread is not closed:
Method: Remove callback mHandler. removeCallbacks (callback hod );