Causes and solutions for Android program memory leakage

Source: Internet
Author: User

Memory leakage is also known as "Storage leakage". The space dynamically opened by the dynamic storage allocation function is not released after use. As a result, this memory unit remains occupied. UntilProgramEnd. Memory leakage.

Memory leakage simply means that a piece of memory space is applied for and is not released after use. Generally, the longer the program runs, the more memory it occupies, and the entire system crashes. A piece of memory applied by the program, and no pointer points to it, the memory will be leaked.

From the perspective of user programs, memory leakage does not cause any harm. As a general user, the memory leakage does not exist. The real danger is the accumulation of Memory leakage, which will eventually consume all the memory of the system. From this point of view, one-time memory leakage is not harmful because it will not accumulate, while implicit memory leakage is very harmful, because it is more difficult to detect than frequent and occasional memory leaks.

Memory leakage of Android applications is caused by the following reasons:

1. The cursor is not closed after the database is queried.
2. convertview is not used to create an adapter.
3. Call recycle () to release the memory when the bitmap object is not in use.
4. objects are referenced by objects with a long life cycle. If an activity is referenced by a static set, the activity cannot be released.

Memory leakage detection:

Use the heap tool in ddms to detect memory overflow.

How to solve Memory leakage:

Use the memory analysis tool MAT (memory analyzer tool) to find Memory leakage objects.

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.