Android Memory Optimization related

Source: Internet
Author: User

How to manage memory in Android

    • Android system memory allocation and recovery methods
      • An app is usually a process that corresponds to a virtual machine
      • GC goes garbage collection only if the heap is not enough space left
      • When the GC triggers, all threads are paused!!!
    • App Memory throttling mechanism
      • Maximum memory limit allocated per app, varies by device
      • Eat large Memory: Pictures
      • Why limit?
    • Background app cleanup mechanism when switching apps
      • LRU Cache when the app is switched
        • LRU algorithm: Most recently used in front, least likely to be cleaned out
      • GC, the ontrimmemory() callback method is executed when scavenging
Android system memory allocation and recovery methods

ADB shell: Enter the android underlying Linux system command;

PS: View the system inside the process of the command;

Dumpsys meminfo com.xxx.xxx: View information about the process

App Memory Optimization method
    • Data
      • Frequent string stitching with StringBuilder
      • Arraymap, Sparearray replace HashMap
      • Memory jitter
      • The smaller class consumes 0.5KB
      • HashMap a entry requires an extra 32KB
    • Object Reuse
      • Resources from the Reuse system
      • Convertview Multiplexing of Listview/gridview
      • Avoid performing object creation in the OnDraw () method
    • Avoid memory leaks
      • Due to a code flaw, this memory, although stopped, is still referenced by other things, causing the GC to not recycle it.
      • Memory leaks cause fewer remaining available heap, frequent triggering of GC

Android Memory Optimization related

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.