Do not know what you do to the Android memory release to do what kind of processing, I contact Android soon, the recent development of small game process, because the game interface components more, just play the game when the feeling is OK, but repeatedly into the game interface play a few times, the game will be Kaka, I instantly have no words, want to go , or memory consumption has not been released, after some learning, although not fully find the root cause, but has eased a lot, here say how I deal with it, and then if everyone has their own good treatment, hope can be shared, so that we can progress together. Here are some of my practices:
First of all, most of the memory-hogging things I know have (general release resources I have in OnDestroy () to do the processing):
1. Picture resources;
2.list occupancy;
3. Array occupancy;
4. The occupancy of other defined methods;
5. Thread callback, thread does not close the problem.
In the face of these problems, my respective methods are:
1. Picture Resource Recycling
private void Recyclebitmap ()
{
if (viewgroup! = null)
{
int count = Viewgroup.getchildcount;
for (int i=0; I <count; 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 occupancy:
Method: List.clear (); Then in the production of empty, do not know if there is no need, but also a word, and there is no exception, so on the way;
3. Array occupancy:
Method: After use is not used after the production of empty;
4. The use of some other defined methods:
Method: Directly to the empty, if there are some list or array inside the method, my method is to define a method of releasing resources in the definition of the method, and then to release the resources to call the method to release the method of internal data, in the empty;
5. Thread callback, thread does not close the problem:
Method: Remove callback Mhandler.removecallbacks (Mmethod);
Android Memory Release processing