Eight common issues that cause APP memory leaks (bottom)

Source: Internet
Author: User

Baidu Search: Xiao Qiang test brand

QQ Group: 138269539

Handlers

Similarly, defining an anonymous Runnable object and committing it to Handler can also lead to activity leaks. The Runnable object indirectly refers to the activity object that defines it, and it is committed to the MessageQueue of Handler, which causes the activity to leak if it is not processed when the activity is destroyed.

Threads

Similarly, using Thread and TimerTask can also lead to activity leaks

Timer Tasks

As long as they are created through anonymous classes, they also hold strong references to activity, which can lead to memory leaks, even though they are executed on separate threads

Sensor Manager

Finally, system services can be obtained through context.getsystemservice, which are responsible for performing some background tasks or providing interfaces for hardware access. If the context object wants to be notified when an event inside the service occurs, it needs to register itself in the listener for the service. However, this will allow the service to have a reference to the activity, and if the programmer forgets to unregister when the activity is destroyed, it will cause the activity to leak.

Now, we've shown eight scenarios where it's easy to inadvertently leak large amounts of memory. Keep in mind that in the worst case scenario, your APP might run out of memory due to a large memory leak, but it's not always like this. Instead, a memory leak consumes a lot of memory, but does not run out of memory, and the APP is garbage collected frequently due to insufficient memory allocation. Garbage collection is a very time-consuming operation that can lead to serious stuttering. Be careful when creating objects inside activity, and often test for memory leaks.

Eight common issues that cause APP memory leaks (bottom)

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.