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