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, due to a lot of game interface components. Just play the game when the feeling is OK, but repeated into the game interface to play a few times, the game will be Kaka, I instantly have no words, want to go. Or the memory footprint is not released, after learning, although not fully found root. But has been relieved very much, here to say how I deal with it, and then if everyone has their own good way of handling, hope to be able to share. So that everyone 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. Occupancy of other defined methods;

5. Thread callback, thread does not close the problem.

In the face of these problems, I have used the following methods:

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 ();
}
}
}
}
}
}
About the release of memory for pictures, let's say some game engines. There should be a clear method that can be used to release memory at the end of an interface by invoking the appropriate method.

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 abnormality. So that's the way.


3. Array occupancy:
Method: After use is not practical after the production of empty.


4. The use of some other defined methods:
Method: Direct air production. Suppose there are lists or arrays inside the method. My approach is to define a method for releasing resources within the defined method. The method then releases the internal data of the method when the resource is being freed, making it empty.


5. Thread callback, thread does not close the problem:
Method: Remove callback Mhandler.removecallbacks (Mmethod);

Android Memory Release processing

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.