Get Your XDA 2015 Custom Avatar and Signature Images Here

As stated in our motto, XDA Developer is for developers, by developers. The … more

Pin Your Photos on Android Lollipop with Photo Pinner

In the last few weeks,we have been talking quite a bit about Android 5.0 Lollipop. This … more

Samsung Galaxy Note Edge Hands On – XDA TV

Perhaps one of the more peculiar announcements this year was the curved edge-screened … more

Nova Launcher Update Brings Lollipop Functionality and Feel

One of the most popular third party launcher on Android, Nova Launcher, has just … more
Post Reply

Android Memory Management - in detail for all those questions regarding task killing

OP diablo009

7th January 2011, 05:55 PM   |  #1  
diablo009's Avatar
OP Senior Member
Flag Atlanta GA
Thanks Meter: 1,344
 
5,540 posts
Join Date:Joined: Apr 2009
More
This is now android works. The way I see this, this is very much similar to "pre-fetch" concept in windows 7.

I have a 6 GB RAM laptop. Base OS uses less than 1.5 GB of RAM. But like an hour or so when I see my RAM usage, its to the tune of 3-4 GB. What I have noticed is that my most frequently/recently used apps are loaded to RAM and kept there idle. Some amount of RAM is always kept free instead of using up all RAM. This way apps start faster. When I load a different memory heavy program, it pushes the existing one out and loads this.

More or less the same in android too. When u go to any task manager app n see the running apps, u'll notice that many of the apps loaded are the ones u use frequently.

These apps do NOT use any CPU. They are just loaded to memory and kept there for quick access.

When I boot up my phone I have like 190+ MB free RAM. Though left in standy mode, within an hour, I see my free RAM fall to 80-120 MB range. I never saw it go less than 80 MB. And the apps in memory are the ones I used the last time, and the ones I use all the time.

Even if u use a task killer to kill these "inactive" apps at intervals, they would be loaded again sooner or later. That's the principle of android. So by using task killers, though u feel u r freeing up memory, in fact, u r only draining ur battery. What's the use of memory if u r not using it effectively.

Don't worry abt free RAM amount. Let android manage it. Systems are intelligent enough these days.

Hope this helps. Below is more about the same in detail.



Android Memory Management

Android is a Linux based OS with 2.6.x kernel, stripped down to handle most tasks pretty well. It uses native open 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 application

Android’s process and memory management is a little unusual. Like Java and .NET, Android uses its own run time and virtual machine to manage application memory. Unlike either of these frameworks, the Android run time also manages the process lifetimes. Android ensures application responsiveness by stopping and killing processes as necessary to free resources for higher-priority applications.

Each Android application runs in a separate process within its own Dalvik instance, relinquishing all responsibility for memory and process management to the Android run time, which stops and kills processes as necessary to manage resources.

Dalvik and the Android run time sit on top of a Linux kernel that handles low-level hardware interaction including drivers and memory management, while a set of APIs provides access to all of the under- lying services, features, and hardware.

Dalvik Virtual Machine Dalvik is a register-based virtual machine that’s been optimized to ensure that a device can run multiple instances efficiently. It relies on the Linux kernel for threading and low-level memory management.

The Dalvik Virtual Machine

One of the key elements of Android is the Dalvik virtual machine. Rather than use a traditional Java virtual machine (VM) such as Java ME (Java Mobile Edition), Android uses its own custom VM designed to ensure that 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.

All Android hardware and system service access is managed using Dalvik as a middle tier. By using a VM to host application execution, developers have an abstraction layer that ensures they never have to worry about a particular 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 supplied within the SDK.

Understanding Application Priority and Process States

The order in which processes are killed to reclaim resources is determined by the priority of the hosted applications. 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 be killed first. Process priority is also affected by interprocess dependencies; if an application has a dependency on a Service or Content Provider supplied by a second application, the secondary application will have at least as high a priority as the application it supports.

All Android applications will remain running and in memory until the system needs its resources for other applications.

It’s important to structure your application correctly to ensure that its priority is appropriate for the work it’s doing. 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 (see the attached image) explaining how the state is determined by the application components comprising it:

Active Processes Active (foreground) processes are those hosting applications with components currently interacting 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.
* 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 when an Activity is only partially obscured (by a non-full-screen or transparent Activity). There are generally very few 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 ongoing processing that should continue without a visible interface. Because Services don’t interact directly with the user, they receive a slightly lower priority than visible Activities. They are still considered to be foreground processes 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 that have been started are considered background processes. There will generally be a large number of background processes that Android will kill using a last-seen-first-killed pat- tern to obtain resources for foreground processes.

Empty Processes To improve overall system performance, Android often retains applications in memory after they have reached the end of their lifetimes. Android maintains this cache to improve the start-up time of applications when they’re re-launched. These processes are rou- tinely killed as required.

How to use memory efficiently

Android manages opened applications which are running in the background, so officially you shouldn’t care about that. This means that it closes the applications when the system needs more memory. However, most android users are not very satisfied with how it does its things because sometimes it leaves too many processes running which causes sluggishness’ in everyday performance. We can use advanced task killer/task manager and it does its job very well.

Source:
Code:
http://mobworld.wordpress.com/2010/07/05/memory-management-in-android/
Attached Thumbnails
Click image for larger version

Name:	processimage.jpg
Views:	2729
Size:	20.1 KB
ID:	483102  
Last edited by diablo009; 8th January 2011 at 05:03 AM. Reason: Changed thread icon
The Following 35 Users Say Thank You to diablo009 For This Useful Post: [ View ]
7th January 2011, 07:32 PM   |  #2  
rickysa2000's Avatar
Senior Member
Thanks Meter: 358
 
304 posts
Join Date:Joined: Nov 2010
Donate to Me
More
Angry NICE!!
Quote:
Originally Posted by diablo009

This is now android works. The way I see this, this is very much similar to "pre-fetch" concept in windows 7.

I have a 6 GB RAM laptop. Base OS uses less than 1.5 GB of RAM. But like an hour or so when I see my RAM usage, its to the tune of 3-4 GB. What I have noticed is that my most frequently/recently used apps are loaded to RAM and kept there idle. Some amount of RAM is always kept free instead of using up all RAM. This way apps start faster. When I load a different memory heavy program, it pushes the existing one out and loads this.

More or less the same in android too. When u go to any task manager app n see the running apps, u'll notice that many of the apps loaded are the ones u use frequently.

These apps do NOT use any CPU. They are just loaded to memory and kept there for quick access.

When I boot up my phone I have like 190+ MB free RAM. Though left in standy mode, within an hour, I see my free RAM fall to 80-120 MB range. I never saw it go less than 80 MB. And the apps in memory are the ones I used the last time, and the ones I use all the time.

Even if u use a task killer to kill these "inactive" apps at intervals, they would be loaded again sooner or later. That's the principle of android. So by using task killers, though u feel u r freeing up memory, in fact, u r only draining ur battery. What's the use of memory if u r not using it effectively.

Don't worry abt free RAM amount. Let android manage it. Systems are intelligent enough these days.

Hope this helps. Below is more about the same in detail.



Android Memory Management

Android is a Linux based OS with 2.6.x kernel, stripped down to handle most tasks pretty well. It uses native open 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 application

Android’s process and memory management is a little unusual. Like Java and .NET, Android uses its own run time and virtual machine to manage application memory. Unlike either of these frameworks, the Android run time also manages the process lifetimes. Android ensures application responsiveness by stopping and killing processes as necessary to free resources for higher-priority applications.

Each Android application runs in a separate process within its own Dalvik instance, relinquishing all responsibility for memory and process management to the Android run time, which stops and kills processes as necessary to manage resources.

Dalvik and the Android run time sit on top of a Linux kernel that handles low-level hardware interaction including drivers and memory management, while a set of APIs provides access to all of the under- lying services, features, and hardware.

Dalvik Virtual Machine Dalvik is a register-based virtual machine that’s been optimized to ensure that a device can run multiple instances efficiently. It relies on the Linux kernel for threading and low-level memory management.

The Dalvik Virtual Machine

One of the key elements of Android is the Dalvik virtual machine. Rather than use a traditional Java virtual machine (VM) such as Java ME (Java Mobile Edition), Android uses its own custom VM designed to ensure that 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.

All Android hardware and system service access is managed using Dalvik as a middle tier. By using a VM to host application execution, developers have an abstraction layer that ensures they never have to worry about a particular 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 supplied within the SDK.

Understanding Application Priority and Process States

The order in which processes are killed to reclaim resources is determined by the priority of the hosted applications. 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 be killed first. Process priority is also affected by interprocess dependencies; if an application has a dependency on a Service or Content Provider supplied by a second application, the secondary application will have at least as high a priority as the application it supports.

All Android applications will remain running and in memory until the system needs its resources for other applications.

It’s important to structure your application correctly to ensure that its priority is appropriate for the work it’s doing. 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 (see the attached image) explaining how the state is determined by the application components comprising it:

Active Processes Active (foreground) processes are those hosting applications with components currently interacting 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.
* 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 when an Activity is only partially obscured (by a non-full-screen or transparent Activity). There are generally very few 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 ongoing processing that should continue without a visible interface. Because Services don’t interact directly with the user, they receive a slightly lower priority than visible Activities. They are still considered to be foreground processes 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 that have been started are considered background processes. There will generally be a large number of background processes that Android will kill using a last-seen-first-killed pat- tern to obtain resources for foreground processes.

Empty Processes To improve overall system performance, Android often retains applications in memory after they have reached the end of their lifetimes. Android maintains this cache to improve the start-up time of applications when they’re re-launched. These processes are rou- tinely killed as required.

How to use memory efficiently

Android manages opened applications which are running in the background, so officially you shouldn’t care about that. This means that it closes the applications when the system needs more memory. However, most android users are not very satisfied with how it does its things because sometimes it leaves too many processes running which causes sluggishness’ in everyday performance. We can use advanced task killer/task manager and it does its job very well.

Source:

Code:
http://mobworld.wordpress.com/2010/07/05/memory-management-in-android/

Sweet!! Good Info.. But wrong Section. You should port this in the General Section to help all!
7th January 2011, 07:36 PM   |  #3  
diablo009's Avatar
OP Senior Member
Flag Atlanta GA
Thanks Meter: 1,344
 
5,540 posts
Join Date:Joined: Apr 2009
More
Quote:
Originally Posted by rickysa2000

Sweet!! Good Info.. But wrong Section. You should port this in the General Section to help all!

Oh. I thought this belongs to Q&A.

Any mods here who can move this to "General" please.
12th January 2011, 10:59 PM   |  #4  
bclark's Avatar
Senior Member
Flag Blue Point
Thanks Meter: 227
 
1,215 posts
Join Date:Joined: Oct 2010
Donate to Me
More
This would be why when you open the built in task manager nothing or only your launcher shows up but when you open ATK multiple other programs are shown open, correct?
12th January 2011, 11:07 PM   |  #5  
trekie86's Avatar
Senior Member
Flag Colorado Springs, CO USA
Thanks Meter: 38
 
437 posts
Join Date:Joined: Jul 2010
More
I found similar information while researching battery saver programs. I keep ATK when I have stubborn apps that are stuck because it is easier to get through than Android Task Manager but the auto-kill feature is always disabled. Good coverage of this info.
12th January 2011, 11:12 PM   |  #6  
diablo009's Avatar
OP Senior Member
Flag Atlanta GA
Thanks Meter: 1,344
 
5,540 posts
Join Date:Joined: Apr 2009
More
Quote:
Originally Posted by bclark

This would be why when you open the built in task manager nothing or only your launcher shows up but when you open ATK multiple other programs are shown open, correct?

Exactly! If all programs/processes show up, like they do in ATK, it could cause instabilities in the system when the user kills any important process knowingly/unknowingly.
12th January 2011, 11:13 PM   |  #7  
diablo009's Avatar
OP Senior Member
Flag Atlanta GA
Thanks Meter: 1,344
 
5,540 posts
Join Date:Joined: Apr 2009
More
Quote:
Originally Posted by trekie86

I found similar information while researching battery saver programs. I keep ATK when I have stubborn apps that are stuck because it is easier to get through than Android Task Manager but the auto-kill feature is always disabled. Good coverage of this info.

Thanks you. Saw too many threads/posts with questions about ATK and killing tasks. So compiled this so they could all be directed to this thread. :)
The Following User Says Thank You to diablo009 For This Useful Post: [ View ]
27th February 2011, 05:29 PM   |  #8  
RaptorOne3's Avatar
Senior Member
Thanks Meter: 30
 
257 posts
Join Date:Joined: Dec 2010
More
I don't mean to go digging up old threads, but I just wanted to post my opinion here on this memory clearing ordeal.

After reading the entire thread, I am even MORE inclined to want to use ATK or something similar...

At the very bottom of the post, last paragraph, it reads -
Quote:

How to use memory efficiently

Android manages opened applications which are running in the background, so officially you shouldn’t care about that. This means that it closes the applications when the system needs more memory. However, most android users are not very satisfied with how it does its things because sometimes it leaves too many processes running which causes sluggishness’ in everyday performance. We can use advanced task killer/task manager and it does its job very well.

Here's my take -

While there is no way to override Dalviks operations for application retention, at least while you're operating the device you can keep the memory clear by monitoring and assisting in clearing it out, manually; Which will in fact yield a performance boost for a duration of time. Based on the description of how Dalvik operates, this is true.

Exactly how long of a duration I don't know. But it is as obvious as it gets that while Dalvik memory management is indeed cool, it is far from perfect and definitely induces low memory situations that CAN in fact cause sluggish performance. That much is already known.

So, in my opinion, if you enjoy the absolute maximum performance out of your device, ATK or something similar is definitely NOT a bad idea. Though it has to be done manually and after a period of time applications are brought back into memory, clearing the memory before opening an application allows full memory access to that application and also inevitably reduces CPU load as it removes the requirement for Dalvik to "shove" other applications on idle off the memory to make room for the active applications.

Personally, I just use Task Manager. It seems much more effective at clearing the memory.
25th March 2011, 07:37 PM   |  #9  
diablo009's Avatar
OP Senior Member
Flag Atlanta GA
Thanks Meter: 1,344
 
5,540 posts
Join Date:Joined: Apr 2009
More
Well, there are times when my phone is on for abt a week or so without turning off or rebooting (the times when I resist flashing roms or kernels or modems) and still I hardly feel any sluggishness. And I do NOT use any task killers. I let android handle everything its way.

And there is a difference between cleaning up memory say once every couple days, and having ATK set up to free up memory every hour or two. The first one could be helpful while the second is a battery killer.
Last edited by diablo009; 25th March 2011 at 07:58 PM.
17th November 2012, 06:04 AM   |  #10  
Senior Member
Flag Mangalore
Thanks Meter: 82
 
264 posts
Join Date:Joined: May 2012
More
Quote:
Originally Posted by rickysa2000

Sweet!! Good Info.. But wrong Section. You should port this in the General Section to help all!

why quote such a big post to tell this


come on

regards

The Following User Says Thank You to strategist99 For This Useful Post: [ View ]
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes