Android Memory Release processing

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.