Memory management in android


Published on

Zybotech Solutions is a professional Mobile Application Training and development company in Kerala. Zybotech combines world class Technology, Process Skills and Expertise to meet the client's requirements round the clock assuring Business as usual. Visit

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Memory management in android

  1. 1. Android Application Development Training Tutorial For more info visit A7, Stephanos Tower, Eachamukku, Kakkanadu,Kochi
  2. 2. Memory Management in AndroidHi, You might be aware of the memory concept of android. Here I have described the basic memory concept inandroid,Introduction about Android memoryAndroidAndroid is a software stack for mobile devices that includes an operating system, middleware and keyapplications. The Android SDK provides the tools and APIs necessary to begin developing applications on theAndroid platform using the Java programming language.Android MemoryAndroid is a Linux based OS with 2.6.x kernel, stripped down to handle most tasks pretty well. It uses nativeopen source C libraries that have powered Linux machines for years. All the basic OS operations like I/O,memory management, and so on, are handled by the native stripped-down Linux kernel.How to use memory for each applicationAndroid’s process and memory management is a little unusual. Like Java and .NET, Android uses its own runtime and virtual machine to manage application memory. Unlike either of these frameworks, the Android runtime also manages the process lifetimes. Android ensures application responsiveness by stopping and killingprocesses as necessary to free resources for higher-priority applications.Each Android application runs in a separate process within its own Dalvik instance, relinquishing allresponsibility for memory and process management to the Android run time, which stops and kills processes asnecessary to manage resources.Dalvik and the Android run time sit on top of a Linux kernel that handles low-level hardware interactionincluding drivers and memory management, while a set of APIs provides access to all of the under- lyingservices, features, and hardware.Dalvik Virtual Machine Dalvik is a register-based virtual machine that’s been optimized to ensure that a devicecan run multiple instances efficiently. It relies on the Linux kernel for threading and low-level memorymanagement.The Dalvik Virtual MachineOne of the key elements of Android is the Dalvik virtual machine. Rather than use a traditional Java virtualmachine (VM) such as Java ME (Java Mobile Edition), Android uses its own custom VM designed to ensurethat multiple instances run efficiently on a single device.The Dalvik VM uses the device’s underlying Linux kernel to handle low-level functionality including security,threading, and process and memory management. A7, Stephanos Tower, Eachamukku, Kakkanadu,Kochi
  3. 3. All Android hardware and system service access is managed using Dalvik as a middle tier. By using a VM tohost application execution, developers have an abstraction layer that ensures they never have to worry about aparticular hardware implementation.The Dalvik VM executes Dalvik executable files, a format optimized to ensure minimal memory foot- print.The .dex executables are created by transforming Java language compiled classes using the tools suppliedwithin the SDK.Understanding Application Priority and Process StatesThe order in which processes are killed to reclaim resources is determined by the priority of the hostedapplications. An application’s priority is equal to its highest-priority component.Where two applications have the same priority, the process that has been at a lower priority longest will bekilled first. Process priority is also affected by interprocess dependencies; if an application has a dependency ona Service or Content Provider supplied by a second application, the secondary application will have at least ashigh a priority as the application it supports.All Android applications will remain running and in memory until the system needs its resources for otherapplications.It’s important to structure your application correctly to ensure that its priority is appropriate for the work it’sdoing. If you don’t, your application could be killed while it’s in the middle of something important.The following list details each of the application states shown in Figure , explaining how the state is determinedby the application components comprising it:Active Processes Active (foreground) processes are those hosting applications with components currentlyinteracting with the user. These are the processes Android is trying to keep responsive by reclaiming resources.There are generally very few of these processes, and they will be killed only as a last resort.Active processes include: Activities in an “active” state; that is, they are in the foreground and responding to user events. You will explore Activity states in greater detail later in this chapter. Activities, Services, or Broadcast Receivers that are currently executing an onReceive event handler. A7, Stephanos Tower, Eachamukku, Kakkanadu,Kochi
  4. 4. Services that are executing an onStart, onCreate, or onDestroy event handler.Visible Processes Visible, but inactive processes are those hosting “visible” Activities. As the name suggests,visible Activities are visible, but they aren’t in the foreground or responding to user events. This happens whenan Activity is only partially obscured (by a non-full-screen or transparent Activity). There are generally veryfew visible processes, and they’ll only be killed in extreme circumstances to allow active processes to continue.Started Service Processes Processes hosting Services that have been started. Services support ongoingprocessing that should continue without a visible interface. Because Services don’t interact directly with theuser, they receive a slightly lower priority than visible Activities. They are still considered to be foregroundprocesses and won’t be killed unless resources are needed for active or visible processes.Background Processes Processes hosting Activities that aren’t visible and that don’t have any Services thathave been started are considered background processes. There will generally be a large number of backgroundprocesses that Android will kill using a last-seen-first-killed pat- tern to obtain resources for foregroundprocesses.Empty Processes To improve overall system performance, Android often retains applications in memory afterthey have reached the end of their lifetimes. Android maintains this cache to improve the start-up time ofapplications when they’re re-launched. These processes are rou- tinely killed as required.How to use memory efficientlyAndroid manages opened applications which are running in the background, so officially you shouldn’t careabout that. This means that it closes the applications when the system needs more memory. However, mostandroid users are not very satisfied with how it does its things because sometimes it leaves too many processesrunning which causes sluggishness’ in everyday performance. We can use advanced task killer/task managerand it does its job very well.I think, Now you might be clear the memory concept of android. I will come soon with tracking the memoryallocation and avoiding the memory leaks. A7, Stephanos Tower, Eachamukku, Kakkanadu,Kochi