SlideShare ist ein Scribd-Unternehmen logo
1 von 38
FabiĂĄn Baptista
@fbaptista
Android Memory
Management
FabiĂĄn Baptista
@fbaptista
Android Memory
Management
Talk about…
Android Architecture
Concepts
How it works
Tools and logs
Under the hood…
• Since Android is built on top of a
Linux Kernel, we should know a little
bit about memory management on
Linux …
• Other key topics that helps a lot:
– Virtual Memory
– Android Activity Lifecycle
– Garbage Collection
– Memory Heap
Architecture
Linux Kernel
• Linux 2.6 + Google architecture
changes.
• Android core functionality is based on
top of Linux
– Hardware interface & drivers
– Memory Management
– Process Management
– Networking
– Security
– Etc.
Architecture
Android Runtime
• Dalvik Virtual Machine
– Like a special Java VM
– Optimized for mobile world
– Not .class -> .dex (bulit from a .class)
– Multiple instances of the VM running
• Core Libraries
– Most of the functionalities of the Java SE
libraries
Architecture
Virtual Memory
• Maps process memory
addresses (virtual) into
physical addresses.
• Hardware: Address
translation inside CPU
(called MMU)
• Software: Extend physical
memory size
Virtual Memory - Key Benefits
• Avoid process to handle a shared
space.
• More security & isolation
• More memory available
• Easier programming / hidden
fragmentation
Concepts
• Swap Space
– Extend physical (full) memory with HD
• Paging
– Uses HD to store & retrieve “pages” of
memory.
– Allow non-contiguous address space for
process
– One of the most important part of typical
Virtual Memory implementation
• Shared Memory
• Heap
Garbage Collection
Garbage Collection
Android Way
• Memory:
– No Swap space, Paging
– Memory mapping
• Shared Memory
– Framework code & resources
– Intercommunication (processes)
– Intensively used
Android Way
• New drivers:
– ASHMEM (re-implemented)
– Low Memory Killer (handle OOM
situations)
• Empty Process
– When a process is terminated, not all
memory is released.
– Reduces response time when user
access same process.
Garbage Collection
1. Pre Gingerbread:
– GC “stops the world”
– Full heap collection
– Pause time often > 100ms
2. Gingerbread and beyond:
– Concurrent (mostly)
– Partial Collections
– Pause time usually < 5ms
Garbage Collection - MsgTypes
• GC_CONCURRENT: Occurs when heap is growing (to
avoid enlarge heap in time)
• GC_EXPLICIT: Triggered when an application calls System.gc(). Don’t use
it!
• GC_FOR_MALLOC: Triggered when the heap is full and the application
needs more memory. (stops app)
• GC_HPROF_DUMP_HEAP: Triggered when an HPROF file is created for
memory analysis
• GC_BEFORE_OOM: (Undocumented) It’s supposed to be triggered when
dalvik heap usage is over 90%
Android App Memory
• Dalvik heap
– Defines logical heap size
– Memory can grow to a defined limit
(defined by the system)
– One single virtual memory range
– Physically non-contiguous (analyzed on
GC)
• Logical size is different than Physical
size
• Hard to know exactly how much RAM
your process are using
Memory Numbers…
Proportional Set Size (PSS)
• PSS is considered by Android as your
physical footprint
• Example of Dalvik Heap usage:
– 20MB of (Private)
– 12MB of Shared (between 4 process)
– PSS = 20 + (12/4) = 23
Memory Numbers…
Private RAM
• Private (Dirty and Clean) is memory
used by the App.
• All heap allocations (Dalvik + Native)
• Memory that will be available if your
process is destroyed.
• Can’t be paged into storage
Memory Numbers…
Low Memory Killer (Linux)
• Look for “bad” process (heuristics):
– High memory consuming is bad
– Long running process are good
– Process with a lot of child process are
bad
– Root processes are good (3% off)
Low Memory Killer (Android)
5 - Empty Process
4 - Background Process
3 - Started Services Process
2 - Visible Process
1 - Active Process Critical Priority
High Priority
Low Priority
Low Memory Killer (Android)
Threshold varies based on RAM size.
aded during booting time from init.rc file)
Memory Pages
(4KB each)
3 Memory Tips 4 Apps
1. Use Services in the right way
– Only one process should take care of UI
– Take care about dependencies
2. Release memory when
– Your UI becomes hidden
– Memory becomes tight
(ComponentCallbacks)
3. Use the right Bitmaps for each screen
resolution
Services
• Application component without UI.
• Can be used to perform long-running
operations in background.
• Inter-process communication
• Provide a client-server model to bind
with
Services State
Started
•startService()
Bound
•bindService()
Services Started
> startService();
•Can run indefinitely
•Even if the activity who
started it is destroyed
•Once it is finished, the service
should stop itself
Services Bound
> bindService();
•Client / Server interface to:
• Request service
• Get results
• IPC
•Bind by one
•Is destroyed only when all of
them unbind
Release Memory On…
• interface hidden:
– implement onTrimMemory() callback
(Activity classes)
• memory becomes tight:
– onTrimMemory() (added in API level 14)
– onLowMemory() (for older versions)
Bitmaps
• Load the bitmap that your app
needs!
– Scale down image to your resolution
– Or you need more than 1 resolution per
image
• API_level <= 10:
Bitmaps
• Load the bitmap that your app
needs!
– Scale down image to your resolution
– Or you need more than 1 resolution per
image
• API_level >= 11: (Honeycomb &
higher)
Tools & logs
– Logs:
• Dalvik Log Messages: All Garbage Collection logs
• ART: Logged when GC are deemed slow:
– GC Pauses > 5ms
– GC duration > 100ms
– Explicit GCs
– Android Device Monitor for tracking
Allocations
– MAT: Eclipse Memory Analyzer Tool
– Monkop: Memory Footprints on real devices
• GC behavior
• RAM footprint
• Threads
• CPU / Network and others
References
• http://www.android-app-market.com/android-
architecture.html
• https://developer.android.com/training/articles/
memory.html
• Android Memory Management
https://gist.github.com/blixtra/ca6e1f289462fe
2679af
• Google I/O 2011: Memory management for Android Apps
https://www.youtube.com/watch?v=_CruQY55
HOk
• Low Ram – Android 4.4 Optimizations
http://source.android.com/devices/tech/low-
ram.html
Thank you

Weitere ähnliche Inhalte

Was ist angesagt?

The Google Bigtable
The Google BigtableThe Google Bigtable
The Google BigtableRomain Jacotin
 
Android Project Presentation
Android Project PresentationAndroid Project Presentation
Android Project PresentationLaxmi Kant Yadav
 
GFS & HDFS Introduction
GFS & HDFS IntroductionGFS & HDFS Introduction
GFS & HDFS IntroductionHariharan Ganesan
 
Scalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsScalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsJonas BonĂŠr
 
Paging and segmentation
Paging and segmentationPaging and segmentation
Paging and segmentationPiyush Rochwani
 
Google File System
Google File SystemGoogle File System
Google File Systemguest2cb4689
 
Mongodb basics and architecture
Mongodb basics and architectureMongodb basics and architecture
Mongodb basics and architectureBishal Khanal
 
08 Operating System Support
08  Operating  System  Support08  Operating  System  Support
08 Operating System SupportJeanie Delos Arcos
 
Distributed Query Processing
Distributed Query ProcessingDistributed Query Processing
Distributed Query ProcessingMythili Kannan
 
NOSQL- Presentation on NoSQL
NOSQL- Presentation on NoSQLNOSQL- Presentation on NoSQL
NOSQL- Presentation on NoSQLRamakant Soni
 
Big Data Analytics with Hadoop
Big Data Analytics with HadoopBig Data Analytics with Hadoop
Big Data Analytics with HadoopPhilippe Julio
 
Distributed design alternatives
Distributed design alternativesDistributed design alternatives
Distributed design alternativesPooja Dixit
 
A Technical Introduction to WiredTiger
A Technical Introduction to WiredTigerA Technical Introduction to WiredTiger
A Technical Introduction to WiredTigerMongoDB
 
Google File System
Google File SystemGoogle File System
Google File SystemJunyoung Jung
 
NOSQL Databases types and Uses
NOSQL Databases types and UsesNOSQL Databases types and Uses
NOSQL Databases types and UsesSuvradeep Rudra
 
HADOOP TECHNOLOGY ppt
HADOOP  TECHNOLOGY pptHADOOP  TECHNOLOGY ppt
HADOOP TECHNOLOGY pptsravya raju
 
Introduction to HDFS
Introduction to HDFSIntroduction to HDFS
Introduction to HDFSBhavesh Padharia
 

Was ist angesagt? (20)

The Google Bigtable
The Google BigtableThe Google Bigtable
The Google Bigtable
 
Android Project Presentation
Android Project PresentationAndroid Project Presentation
Android Project Presentation
 
GFS & HDFS Introduction
GFS & HDFS IntroductionGFS & HDFS Introduction
GFS & HDFS Introduction
 
Scalability, Availability & Stability Patterns
Scalability, Availability & Stability PatternsScalability, Availability & Stability Patterns
Scalability, Availability & Stability Patterns
 
Paging and segmentation
Paging and segmentationPaging and segmentation
Paging and segmentation
 
Google File System
Google File SystemGoogle File System
Google File System
 
Mongodb basics and architecture
Mongodb basics and architectureMongodb basics and architecture
Mongodb basics and architecture
 
GOOGLE BIGTABLE
GOOGLE BIGTABLEGOOGLE BIGTABLE
GOOGLE BIGTABLE
 
08 Operating System Support
08  Operating  System  Support08  Operating  System  Support
08 Operating System Support
 
Distributed Query Processing
Distributed Query ProcessingDistributed Query Processing
Distributed Query Processing
 
NOSQL- Presentation on NoSQL
NOSQL- Presentation on NoSQLNOSQL- Presentation on NoSQL
NOSQL- Presentation on NoSQL
 
Big Data Analytics with Hadoop
Big Data Analytics with HadoopBig Data Analytics with Hadoop
Big Data Analytics with Hadoop
 
Distributed design alternatives
Distributed design alternativesDistributed design alternatives
Distributed design alternatives
 
Memory Management
Memory ManagementMemory Management
Memory Management
 
A Technical Introduction to WiredTiger
A Technical Introduction to WiredTigerA Technical Introduction to WiredTiger
A Technical Introduction to WiredTiger
 
Google File System
Google File SystemGoogle File System
Google File System
 
Amazon Simpledb
Amazon Simpledb Amazon Simpledb
Amazon Simpledb
 
NOSQL Databases types and Uses
NOSQL Databases types and UsesNOSQL Databases types and Uses
NOSQL Databases types and Uses
 
HADOOP TECHNOLOGY ppt
HADOOP  TECHNOLOGY pptHADOOP  TECHNOLOGY ppt
HADOOP TECHNOLOGY ppt
 
Introduction to HDFS
Introduction to HDFSIntroduction to HDFS
Introduction to HDFS
 

Andere mochten auch

Memory management in Android
Memory management in AndroidMemory management in Android
Memory management in AndroidKeyhan Asghari
 
Android memory fundamentals
Android memory fundamentalsAndroid memory fundamentals
Android memory fundamentalsTaras Leskiv
 
Memory Management in Android
Memory Management in AndroidMemory Management in Android
Memory Management in AndroidOpersys inc.
 
Android Memory , Where is all My RAM
Android Memory , Where is all My RAM Android Memory , Where is all My RAM
Android Memory , Where is all My RAM Yossi Elkrief
 
Memory management for_android_apps
Memory management for_android_appsMemory management for_android_apps
Memory management for_android_appsBin Shao
 
lightning talk : Android memory leak
lightning talk :  Android memory leaklightning talk :  Android memory leak
lightning talk : Android memory leakDeivison Sporteman
 
Identifying memory leaks in Android applications
Identifying memory leaks in Android applicationsIdentifying memory leaks in Android applications
Identifying memory leaks in Android applicationsZachary Blair
 
Tuning Android for low RAM
Tuning Android for low RAMTuning Android for low RAM
Tuning Android for low RAMChris Simmonds
 
Android - Preventing common memory leaks
Android - Preventing common memory leaksAndroid - Preventing common memory leaks
Android - Preventing common memory leaksAli Muzaffar
 
Android ppt
Android pptAndroid ppt
Android pptsrikanth982
 
Memory management in Linux
Memory management in LinuxMemory management in Linux
Memory management in LinuxRaghu Udiyar
 
Memory Analysis of the Dalvik (Android) Virtual Machine
Memory Analysis of the Dalvik (Android) Virtual MachineMemory Analysis of the Dalvik (Android) Virtual Machine
Memory Analysis of the Dalvik (Android) Virtual MachineAndrew Case
 
Xamarin.android memory management gotchas
Xamarin.android memory management gotchasXamarin.android memory management gotchas
Xamarin.android memory management gotchasAlec Tucker
 
Vietnam Mobile Day 2013: Memory Management For Android Apps
Vietnam Mobile Day 2013: Memory Management For Android AppsVietnam Mobile Day 2013: Memory Management For Android Apps
Vietnam Mobile Day 2013: Memory Management For Android AppsGameLandVN
 
What's new in Android M
What's new in Android MWhat's new in Android M
What's new in Android MSergey Bandysik
 
Advanced Memory Management on iOS and Android - Mark Probst and Rodrigo Kumpera
Advanced Memory Management on iOS and Android - Mark Probst and Rodrigo KumperaAdvanced Memory Management on iOS and Android - Mark Probst and Rodrigo Kumpera
Advanced Memory Management on iOS and Android - Mark Probst and Rodrigo KumperaXamarin
 

Andere mochten auch (20)

Memory management in Android
Memory management in AndroidMemory management in Android
Memory management in Android
 
Android memory fundamentals
Android memory fundamentalsAndroid memory fundamentals
Android memory fundamentals
 
Memory in Android
Memory in AndroidMemory in Android
Memory in Android
 
Memory Management in Android
Memory Management in AndroidMemory Management in Android
Memory Management in Android
 
Android Memory , Where is all My RAM
Android Memory , Where is all My RAM Android Memory , Where is all My RAM
Android Memory , Where is all My RAM
 
Memory management for_android_apps
Memory management for_android_appsMemory management for_android_apps
Memory management for_android_apps
 
lightning talk : Android memory leak
lightning talk :  Android memory leaklightning talk :  Android memory leak
lightning talk : Android memory leak
 
Identifying memory leaks in Android applications
Identifying memory leaks in Android applicationsIdentifying memory leaks in Android applications
Identifying memory leaks in Android applications
 
Tuning Android for low RAM
Tuning Android for low RAMTuning Android for low RAM
Tuning Android for low RAM
 
Android - Preventing common memory leaks
Android - Preventing common memory leaksAndroid - Preventing common memory leaks
Android - Preventing common memory leaks
 
Android ppt
Android pptAndroid ppt
Android ppt
 
Linux Memory Management
Linux Memory ManagementLinux Memory Management
Linux Memory Management
 
Android ppt
Android pptAndroid ppt
Android ppt
 
Memory management in Linux
Memory management in LinuxMemory management in Linux
Memory management in Linux
 
Android dev
Android devAndroid dev
Android dev
 
Memory Analysis of the Dalvik (Android) Virtual Machine
Memory Analysis of the Dalvik (Android) Virtual MachineMemory Analysis of the Dalvik (Android) Virtual Machine
Memory Analysis of the Dalvik (Android) Virtual Machine
 
Xamarin.android memory management gotchas
Xamarin.android memory management gotchasXamarin.android memory management gotchas
Xamarin.android memory management gotchas
 
Vietnam Mobile Day 2013: Memory Management For Android Apps
Vietnam Mobile Day 2013: Memory Management For Android AppsVietnam Mobile Day 2013: Memory Management For Android Apps
Vietnam Mobile Day 2013: Memory Management For Android Apps
 
What's new in Android M
What's new in Android MWhat's new in Android M
What's new in Android M
 
Advanced Memory Management on iOS and Android - Mark Probst and Rodrigo Kumpera
Advanced Memory Management on iOS and Android - Mark Probst and Rodrigo KumperaAdvanced Memory Management on iOS and Android - Mark Probst and Rodrigo Kumpera
Advanced Memory Management on iOS and Android - Mark Probst and Rodrigo Kumpera
 

Ähnlich wie Memory management in Andoid

Day 7 - Make it Fast
Day 7 - Make it FastDay 7 - Make it Fast
Day 7 - Make it FastBarry Jones
 
Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)MongoDB
 
UWP apps development - Part 3
UWP apps development - Part 3UWP apps development - Part 3
UWP apps development - Part 3Jiri Danihelka
 
Deployment Strategies
Deployment StrategiesDeployment Strategies
Deployment StrategiesMongoDB
 
Drupal performance
Drupal performanceDrupal performance
Drupal performancePiyuesh Kumar
 
Cloud computing UNIT 2.1 presentation in
Cloud computing UNIT 2.1 presentation inCloud computing UNIT 2.1 presentation in
Cloud computing UNIT 2.1 presentation inRahulBhole12
 
A Taste of Monitoring and Post Mortem Debugging with Node
A Taste of Monitoring and Post Mortem Debugging with Node A Taste of Monitoring and Post Mortem Debugging with Node
A Taste of Monitoring and Post Mortem Debugging with Node ibmwebspheresoftware
 
Deployment Strategy
Deployment StrategyDeployment Strategy
Deployment StrategyMongoDB
 
08 operating system support
08 operating system support08 operating system support
08 operating system supportdilip kumar
 
08 operating system support
08 operating system support08 operating system support
08 operating system supportBitta_man
 
Alfresco tuning part1
Alfresco tuning part1Alfresco tuning part1
Alfresco tuning part1Luis Cabaceira
 
Alfresco tuning part1
Alfresco tuning part1Alfresco tuning part1
Alfresco tuning part1Luis Cabaceira
 
Taboola's experience with Apache Spark (presentation @ Reversim 2014)
Taboola's experience with Apache Spark (presentation @ Reversim 2014)Taboola's experience with Apache Spark (presentation @ Reversim 2014)
Taboola's experience with Apache Spark (presentation @ Reversim 2014)tsliwowicz
 
Silicon Valley Code Camp 2014 - Advanced MongoDB
Silicon Valley Code Camp 2014 - Advanced MongoDBSilicon Valley Code Camp 2014 - Advanced MongoDB
Silicon Valley Code Camp 2014 - Advanced MongoDBDaniel Coupal
 
TechGIG_Memory leaks in_java_webnair_26th_july_2012
TechGIG_Memory leaks in_java_webnair_26th_july_2012TechGIG_Memory leaks in_java_webnair_26th_july_2012
TechGIG_Memory leaks in_java_webnair_26th_july_2012Ashish Bhasin
 
Building Real World Applications using Windows Azure - Scott Guthrie, 2nd Dec...
Building Real World Applications using Windows Azure - Scott Guthrie, 2nd Dec...Building Real World Applications using Windows Azure - Scott Guthrie, 2nd Dec...
Building Real World Applications using Windows Azure - Scott Guthrie, 2nd Dec...Vikas Sahni
 
Building azure applications ireland
Building azure applications irelandBuilding azure applications ireland
Building azure applications irelandMichael Meagher
 
Lecture 12 monitoring the network
Lecture 12   monitoring the networkLecture 12   monitoring the network
Lecture 12 monitoring the networkWiliam Ferraciolli
 

Ähnlich wie Memory management in Andoid (20)

Day 7 - Make it Fast
Day 7 - Make it FastDay 7 - Make it Fast
Day 7 - Make it Fast
 
Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)
 
UWP apps development - Part 3
UWP apps development - Part 3UWP apps development - Part 3
UWP apps development - Part 3
 
Deployment Strategies
Deployment StrategiesDeployment Strategies
Deployment Strategies
 
Android OS
Android OSAndroid OS
Android OS
 
Drupal performance
Drupal performanceDrupal performance
Drupal performance
 
Cloud computing UNIT 2.1 presentation in
Cloud computing UNIT 2.1 presentation inCloud computing UNIT 2.1 presentation in
Cloud computing UNIT 2.1 presentation in
 
A Taste of Monitoring and Post Mortem Debugging with Node
A Taste of Monitoring and Post Mortem Debugging with Node A Taste of Monitoring and Post Mortem Debugging with Node
A Taste of Monitoring and Post Mortem Debugging with Node
 
Deployment Strategy
Deployment StrategyDeployment Strategy
Deployment Strategy
 
08 operating system support
08 operating system support08 operating system support
08 operating system support
 
08 operating system support
08 operating system support08 operating system support
08 operating system support
 
Alfresco tuning part1
Alfresco tuning part1Alfresco tuning part1
Alfresco tuning part1
 
Alfresco tuning part1
Alfresco tuning part1Alfresco tuning part1
Alfresco tuning part1
 
Taboola's experience with Apache Spark (presentation @ Reversim 2014)
Taboola's experience with Apache Spark (presentation @ Reversim 2014)Taboola's experience with Apache Spark (presentation @ Reversim 2014)
Taboola's experience with Apache Spark (presentation @ Reversim 2014)
 
Silicon Valley Code Camp 2014 - Advanced MongoDB
Silicon Valley Code Camp 2014 - Advanced MongoDBSilicon Valley Code Camp 2014 - Advanced MongoDB
Silicon Valley Code Camp 2014 - Advanced MongoDB
 
Mini-Training: To cache or not to cache
Mini-Training: To cache or not to cacheMini-Training: To cache or not to cache
Mini-Training: To cache or not to cache
 
TechGIG_Memory leaks in_java_webnair_26th_july_2012
TechGIG_Memory leaks in_java_webnair_26th_july_2012TechGIG_Memory leaks in_java_webnair_26th_july_2012
TechGIG_Memory leaks in_java_webnair_26th_july_2012
 
Building Real World Applications using Windows Azure - Scott Guthrie, 2nd Dec...
Building Real World Applications using Windows Azure - Scott Guthrie, 2nd Dec...Building Real World Applications using Windows Azure - Scott Guthrie, 2nd Dec...
Building Real World Applications using Windows Azure - Scott Guthrie, 2nd Dec...
 
Building azure applications ireland
Building azure applications irelandBuilding azure applications ireland
Building azure applications ireland
 
Lecture 12 monitoring the network
Lecture 12   monitoring the networkLecture 12   monitoring the network
Lecture 12 monitoring the network
 

KĂźrzlich hochgeladen

Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfWilly Marroquin (WillyDevNET)
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 

KĂźrzlich hochgeladen (20)

Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 

Memory management in Andoid

  • 4. Under the hood… • Since Android is built on top of a Linux Kernel, we should know a little bit about memory management on Linux … • Other key topics that helps a lot: – Virtual Memory – Android Activity Lifecycle – Garbage Collection – Memory Heap
  • 6. Linux Kernel • Linux 2.6 + Google architecture changes. • Android core functionality is based on top of Linux – Hardware interface & drivers – Memory Management – Process Management – Networking – Security – Etc.
  • 8. Android Runtime • Dalvik Virtual Machine – Like a special Java VM – Optimized for mobile world – Not .class -> .dex (bulit from a .class) – Multiple instances of the VM running • Core Libraries – Most of the functionalities of the Java SE libraries
  • 10. Virtual Memory • Maps process memory addresses (virtual) into physical addresses. • Hardware: Address translation inside CPU (called MMU) • Software: Extend physical memory size
  • 11. Virtual Memory - Key Benefits • Avoid process to handle a shared space. • More security & isolation • More memory available • Easier programming / hidden fragmentation
  • 12. Concepts • Swap Space – Extend physical (full) memory with HD • Paging – Uses HD to store & retrieve “pages” of memory. – Allow non-contiguous address space for process – One of the most important part of typical Virtual Memory implementation • Shared Memory • Heap
  • 15. Android Way • Memory: – No Swap space, Paging – Memory mapping • Shared Memory – Framework code & resources – Intercommunication (processes) – Intensively used
  • 16. Android Way • New drivers: – ASHMEM (re-implemented) – Low Memory Killer (handle OOM situations) • Empty Process – When a process is terminated, not all memory is released. – Reduces response time when user access same process.
  • 17. Garbage Collection 1. Pre Gingerbread: – GC “stops the world” – Full heap collection – Pause time often > 100ms 2. Gingerbread and beyond: – Concurrent (mostly) – Partial Collections – Pause time usually < 5ms
  • 18. Garbage Collection - MsgTypes • GC_CONCURRENT: Occurs when heap is growing (to avoid enlarge heap in time) • GC_EXPLICIT: Triggered when an application calls System.gc(). Don’t use it! • GC_FOR_MALLOC: Triggered when the heap is full and the application needs more memory. (stops app) • GC_HPROF_DUMP_HEAP: Triggered when an HPROF file is created for memory analysis • GC_BEFORE_OOM: (Undocumented) It’s supposed to be triggered when dalvik heap usage is over 90%
  • 19. Android App Memory • Dalvik heap – Defines logical heap size – Memory can grow to a defined limit (defined by the system) – One single virtual memory range – Physically non-contiguous (analyzed on GC) • Logical size is different than Physical size • Hard to know exactly how much RAM your process are using
  • 21. Proportional Set Size (PSS) • PSS is considered by Android as your physical footprint • Example of Dalvik Heap usage: – 20MB of (Private) – 12MB of Shared (between 4 process) – PSS = 20 + (12/4) = 23
  • 23. Private RAM • Private (Dirty and Clean) is memory used by the App. • All heap allocations (Dalvik + Native) • Memory that will be available if your process is destroyed. • Can’t be paged into storage
  • 25. Low Memory Killer (Linux) • Look for “bad” process (heuristics): – High memory consuming is bad – Long running process are good – Process with a lot of child process are bad – Root processes are good (3% off)
  • 26. Low Memory Killer (Android) 5 - Empty Process 4 - Background Process 3 - Started Services Process 2 - Visible Process 1 - Active Process Critical Priority High Priority Low Priority
  • 27. Low Memory Killer (Android) Threshold varies based on RAM size. aded during booting time from init.rc file) Memory Pages (4KB each)
  • 28. 3 Memory Tips 4 Apps 1. Use Services in the right way – Only one process should take care of UI – Take care about dependencies 2. Release memory when – Your UI becomes hidden – Memory becomes tight (ComponentCallbacks) 3. Use the right Bitmaps for each screen resolution
  • 29. Services • Application component without UI. • Can be used to perform long-running operations in background. • Inter-process communication • Provide a client-server model to bind with
  • 31. Services Started > startService(); •Can run indefinitely •Even if the activity who started it is destroyed •Once it is finished, the service should stop itself
  • 32. Services Bound > bindService(); •Client / Server interface to: • Request service • Get results • IPC •Bind by one •Is destroyed only when all of them unbind
  • 33. Release Memory On… • interface hidden: – implement onTrimMemory() callback (Activity classes) • memory becomes tight: – onTrimMemory() (added in API level 14) – onLowMemory() (for older versions)
  • 34. Bitmaps • Load the bitmap that your app needs! – Scale down image to your resolution – Or you need more than 1 resolution per image • API_level <= 10:
  • 35. Bitmaps • Load the bitmap that your app needs! – Scale down image to your resolution – Or you need more than 1 resolution per image • API_level >= 11: (Honeycomb & higher)
  • 36. Tools & logs – Logs: • Dalvik Log Messages: All Garbage Collection logs • ART: Logged when GC are deemed slow: – GC Pauses > 5ms – GC duration > 100ms – Explicit GCs – Android Device Monitor for tracking Allocations – MAT: Eclipse Memory Analyzer Tool – Monkop: Memory Footprints on real devices • GC behavior • RAM footprint • Threads • CPU / Network and others
  • 37. References • http://www.android-app-market.com/android- architecture.html • https://developer.android.com/training/articles/ memory.html • Android Memory Management https://gist.github.com/blixtra/ca6e1f289462fe 2679af • Google I/O 2011: Memory management for Android Apps https://www.youtube.com/watch?v=_CruQY55 HOk • Low Ram – Android 4.4 Optimizations http://source.android.com/devices/tech/low- ram.html

Hinweis der Redaktion

  1. Android is a linux-based embedded operating system for mobile devices such as smart phones and tablets. It is open source. It supports many architectures like ARM, MIPS, X86. It uses modified linux kernel 2.6. Linux Kernel type is monolithic. Even though android uses linux kernel but it varies in some of the core components.
  2. Surface Manager: It is used for compositing window manager with off-screen buffering. Off-screen buffering means you cant directly draw into the screen, but your drawings go to the off-screen buffer. There it is combined with other drawings and form the final screen the user will see. This off screen buffer is the reason behind the transparency of windows. Media framework: Media framework provides different media codecs allowing the recording and playback of different media formats SQLite: SQLite is the database engine used in android for data storage purposes WebKit: It is the browser engine used to display HTML content OpenGL: Used to render 2D or 3D graphics content to the screen
  3. Dalvik Virtual Machine It is a type of JVM used in android devices to run apps and is optimized for low processing power and low memory environments. Unlike the JVM, the Dalvik Virtual Machine doesn’t run .class files, instead it runs .dex files. .dex files are built from .class file at the time of compilation and provides higher efficiency in low resource environments. The Dalvik VM allows multiple instance of Virtual machine to be created simultaneously providing security, isolation, memory management and threading support. It is developed by Dan Bornstein of Google. Core Java Libraries These are different from Java SE and Java ME libraries. However these libraries provides most of the functionalities defined in the Java SE libraries.
  4. These are the blocks that our applications directly interacts with. These programs manage the basic functions of phone like resource management, voice call management etc. As a developer, you just consider these are some basic tools with which we are building our applications. Important blocks of Application framework are: Activity Manager: Manages the activity life cycle of applications Content Providers: Manage the data sharing between applications Telephony Manager: Manages all voice calls. We use telephony manager if we want to access voice calls in our application. Location Manager: Location management, using GPS or cell tower Resource Manager: Manage the various types of resources we use in our Application
  5. Android does not offer swap space for memory, but it does use paging and memory-mapping (mmapping) to manage memory. This means that any memory you modify—whether by allocating new objects or touching mmapped pages—remains resident in RAM and cannot be paged out. So the only way to completely release memory from your app is to release object references you may be holding, making the memory available to the garbage collector. That is with one exception: any files mmapped in without modification, such as code, can be paged out of RAM if the system wants to use that memory elsewhere. Sharing Memory: In order to fit everything it needs in RAM, Android tries to share RAM pages across processes.
  6. Android does not offer swap space for memory, but it does use paging and memory-mapping (mmapping) to manage memory. This means that any memory you modify—whether by allocating new objects or touching mmapped pages—remains resident in RAM and cannot be paged out. So the only way to completely release memory from your app is to release object references you may be holding, making the memory available to the garbage collector. That is with one exception: any files mmapped in without modification, such as code, can be paged out of RAM if the system wants to use that memory elsewhere. Sharing Memory: In order to fit everything it needs in RAM, Android tries to share RAM pages across processes.
  7. Pre gingerbread: All app threads where paused when GC is working. Post gingerbread concurrent GC was implemented (Non-stop)
  8. https://sites.google.com/site/pyximanew/blog/androidunderstandingddmslogcatmemoryoutputmessages GC_EXTERNAL_MALLOC: Used for externally allocated memory like bitmaps and NIO direct bytebuffers. This is only on pre-Honeycomb devices because from Honeycomb the external memory is allocated inside dalvik heap
  9. It stores oom adj (out of memory adjust) values for each group of processes, oom adj value ranges from -17 to 16. It also stores memory(minfree) thresholds for each group of processes at which this group processes gets killed. All these oom adj and minfree thresholds are stored in init.rc file. Kernel reads these minfree, oom adj values from init.rc during booting time[13]. From table 3.1, low memory killer starts killing processes whose oom adj value > 15 when free memory falls down less than 32MB (8192*4KB). Similarly low memory killer starts killing processes whose oom adj value > 14 when free memory falls down less than 28MB (7168*4KB) like that for all. Memory thresholds are varies based on RAM size. The values in table 3.1 are taken from a android OS mobile,with RAM size as 512MB. These static minfree values causes to many problems regarding responsive time of a process and battery life time. More details on these problems explained in chapter 05.
  10.  If you are going to split your app into multiple processes, only one process should be responsible for UI. Other processes should avoid any UI, as this will quickly increase the RAM required by the process (especially once you start loading bitmap assets and other resources). It may then be hard or impossible to reduce the memory usage once the UI is drawn. Additionally, when running more than one process, it's more important than ever that you keep your code as lean as possible, because any unnecessary RAM overhead for common implementations are now replicated in each process. For example, if you are using enums (though you should not use enums), all of the RAM needed to create and initialize those constants is duplicated in each process, and any abstractions you have with adapters and temporaries or other overhead will likewise be replicated. Another concern with multiple processes is the dependencies that exist between them. For example, if your app has a content provider that you have running in the default process which also hosts your UI, then code in a background process that uses that content provider will also require that your UI process remain in RAM. If your goal is to have a background process that can run independently of a heavy-weight UI process, it can't have dependencies on content providers or services that execute in the UI process.
  11. https://developer.android.com/guide/components/services.html A Service is an application component that can perform long-running operations in the background and does not provide a user interface. Another application component can start a service and it will continue to run in the background even if the user switches to another application. Additionally, a component can bind to a service to interact with it and even perform interprocess communication (IPC). For example, a service might handle network transactions, play music, perform file I/O, or interact with a content provider, all from the background.
  12. https://developer.android.com/guide/components/services.html A Service is an application component that can perform long-running operations in the background and does not provide a user interface. Another application component can start a service and it will continue to run in the background even if the user switches to another application. Additionally, a component can bind to a service to interact with it and even perform inter-process communication (IPC). For example, a service might handle network transactions, play music, perform file I/O, or interact with a content provider, all from the background.
  13. https://developer.android.com/guide/components/services.html A Service is an application component that can perform long-running operations in the background and does not provide a user interface. Another application component can start a service and it will continue to run in the background even if the user switches to another application. Additionally, a component can bind to a service to interact with it and even perform inter-process communication (IPC). For example, a service might handle network transactions, play music, perform file I/O, or interact with a content provider, all from the background.
  14. https://developer.android.com/guide/components/services.html A Service is an application component that can perform long-running operations in the background and does not provide a user interface. Another application component can start a service and it will continue to run in the background even if the user switches to another application. Additionally, a component can bind to a service to interact with it and even perform inter-process communication (IPC). For example, a service might handle network transactions, play music, perform file I/O, or interact with a content provider, all from the background.
  15. When the user navigates to a different app and your UI is no longer visible, you should release any resources that are used by only your UI. Releasing UI resources at this time can significantly increase the system's capacity for cached processes, which has a direct impact on the quality of the user experience. To be notified when the user exits your UI, implement the onTrimMemory() callback in your Activity classes. You should use this method to listen for the TRIM_MEMORY_UI_HIDDEN level, which indicates your UI is now hidden from view and you should free resources that only your UI uses. Notice that your app receives the onTrimMemory() callback with TRIM_MEMORY_UI_HIDDEN only when all the UI components of your app process become hidden from the user. This is distinct from the onStop() callback, which is called when an Activity instance becomes hidden, which occurs even when the user moves to another activity in your app. So although you should implement onStop() to release activity resources such as a network connection or to unregister broadcast receivers, you usually should not release your UI resources until you receive onTrimMemory(TRIM_MEMORY_UI_HIDDEN). This ensures that if the user navigates back from another activity in your app, your UI resources are still available to resume the activity quickly.