Android Best performance Practice (ii)--Analyze memory usage

Source: Internet
Author: User

Since Android is an operating system developed for mobile devices, we should always take the memory issue into account when developing applications. Although the Android system has a garbage collection mechanism, this does not mean that we can completely ignore when to allocate or free memory. Even if we all follow the programming recommendations given in the previous article to write programs, there is a good chance of memory leaks or other types of memory problems. So the only way to solve the problem is to try to analyze the memory usage of the application, and this article will teach you how to analyze it. If you haven't read the previous article, it's recommended to read the best Android Performance Practice (a)--manage the memory properly .

Although the current cell phone memory is very large, but we all know that the system is not possible to allocate all the memory to our application. Yes, each program will have a memory limit that can be used, which is called the heap size. Different mobile phones, heap size is not the same, with the current hardware equipment is increasing, the heap size is already from Nexus One 32MB, the Nexus 5 o'clock 192MB. If you want to know what the heap size of your phone is, you can call the following code:

[Java] view plaincopy
  1. Activitymanager manager = (Activitymanager) getsystemservice (Context.activity_service);
  2. int heapsize = Manager.getlargememoryclass ();

The result is returned in megabytes, where the memory used to develop the application does not exceed this limit, or outofmemoryerror will occur. Therefore, for example, in our program we need to cache some data, we can determine the capacity of the cache data according to the heap size.

Android Best performance Practice (ii)--Analyze memory usage

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.