Android Memory Leak summary

Source: Internet
Author: User

Android may have a memory leak where the summary:

1. Querying the database without closing cursors

2. When building adapter, no cached Convertview is used

3.Bitmap object is not used when calling the Recycle () method to free memory

4. Releasing a reference to an object

5. Singleton mode refers to context, if using actvitiy-context, can cause memory leak,

can use Getapplicationcontext ()); or Getapplication () instead.

Reference Documentation:

A?n?d?r?o? i?d?????

Http://wenku.baidu.com/view/3dbfb0a1b0717fd5360cdc47.html

Ways to analyze memory leaks:

1. Analyze memory leaks using the mat

2. Use Procrank to record memory movements

Use Procrank to keep track of the use of a process which we often rely on with scripts. This allows you to see the memory changes for a certain period of time.
If you create a file: trackmem.sh chmod 775 trackmem.sh
The contents are as follows:
#!/bin/bash

While true; Do
ADB Shell Procrank | grep "Com.example.studymemroyleak"
Sleep 1
Done
Run the script:
./trackmem.sh

The purpose of this script is to let the system output the memory usage of the specified process once every 1 seconds, mainly to observe the USS data, can directly output data to the XLS table

./trackmem.sh > Data.xls

Then generate a line chart (choose to draw only lines), and note the units (K) of the numbers. When you create a chart, you select the data, and then you insert the chart.

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.