Memory leaks for Android performance tests

Source: Internet
Author: User

1. What is a memory leak?A memory leak is a request to the system for memory use, but does not return (release), resulting in the memory can neither be used by themselves nor by others. 2. What is the difference between a memory leak and a memory overflow?Memory leaks are allocated out of memory that cannot be reclaimed.A memory overflow is a program that uses more memory than the system can give. 3. How can I derive a memory leak from the test data?First, we need to use performance testing tools to monitor performance data, and Android can use GT.APK (: http://gt.tencent.com/) to monitor memory data. Then, repeat the exact same operation repeatedly for the test object. The test results (memory) are then made into a line chart. A memory leak can be determined if the memory continues to grow in a few identical operations. 4. What causes a memory leak?The ultimate reason for the Android memory leak is that multi-threaded applications repeatedly request to release memory, but the release does not correspond to the application, resulting in eating memory. See Song Baohua's blog http://blog.csdn.net/21cnbao/article/details/7706671. The following is the original blog:memory leaks are divided into two realms, one is dead, the money is not spent, your malloc memory has not released the process of death, we say that the problem in Linux does not exist, the process is a resource encapsulation unit, process hangs, the resources will be released by the kernel, When I die, there's only one zombie. The second realm is that people live, the money is gone, this problem is the real worry of Linux, a multi-threaded program, the process of repeated application and release memory, but the release of the application does not correspond, slowly eat memory, the process of memory consumption curve rise, until the memory depletion. So, in the Linux world, we don't have to worry about people dying, the money is not over the problem, the party will help us deal with. What we have to worry about is that people are alive and the money is out of the question.
Therefore, the process that can be terminated early ends early, and the freed memory in multiple threads is released as early as possible.child shoes that do not understand processes and threads can refer to this articleVerySimple and clear: http://www.ruanyifeng.cOm/blog/2013/04/processes_and_threads.html5. How can I avoid memory leaks?1. A reference to the context object is maintained for a long time. Refer to the Official blog: http://android-developers.blogspot.com/2009/01/avoiding-memory-leaks.html.Reference:In Android applications, many operations use the context object, but most of them are used to load and access resources. This is why all display controls require a context object as a parameter to the constructor method. There are two kinds of context objects commonly used in Android applications: Activity and application. The common practice when a class or method requires a context object is to use the first as the context parameter.   But this means that the View object keeps a reference to the entire activity, so it keeps a reference to everything in the activity, that is, the entire view structure and all of its resources are not recovered in a timely manner, and the long-term reference to the activity is relatively covert. 2. Other circumstances can refer to this blog post, written quite detailed, I have not time to see, after reading a simple analysis.Android memory leak debugging learning and summaryhttp://mzh3344258.blog.51cto.com/1823534/895093

Memory leaks for Android performance tests

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.