`
fonter
  • 浏览: 871138 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

(转)内存管理Memory Management in Android

阅读更多

下载Android安安软件请到:http://code.google.com/p/andbox

 

文章来自:http://mobworld.wordpress.com/2010/07/05/memory-management-in-android/ 有很好的学习价值。

 

Hi, You might be aware of the memory concept of android. Here I have described the basic  memory concept in android,

Introduction about Android memory

Android

Android is a software stack for mobile devices that includes an operating system, middleware and key applications. The Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language.

Android Memory

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.

center
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 , 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.

I think,  Now you might be clear the memory concept of android. I will come soon with tracking the memory allocation and avoiding the memory leaks.

分享到:
评论

相关推荐

    androidsdk-platforms-android-27.rar

    8. **优化的Memory Management**:Android 8.1对内存管理进行了优化,提升了应用启动速度,减少了内存泄漏,提高了整体性能。 9. **安全与隐私**:Android 27增强了安全性和隐私保护,包括更严格的权限管理系统,...

    android面试问题

    Android采用分页内存管理,没有硬件MMU(Memory Management Unit),因此需要软件模拟MMU功能,以确保高效且安全地分配和回收内存。此外,Android会根据应用程序的实时需求进行内存的动态调整,避免内存泄漏,并且...

    AndroidFresoDemo

    4. **Bitmap Memory Management**: Fresco 使用其自己的内存管理系统,防止因大图片导致的内存溢出,通过解码后的图片数据存储在 ashmem(Android 系统的共享内存)中,而非直接占用应用程序的堆内存。 5. **...

    ARM入门 基础知识

    在ARM系统中,内存分为I/O空间和存储空间,通过MMU(Memory Management Unit)进行地址映射,确保程序能正确访问内存。MMU还支持虚拟地址到物理地址的转换,实现内存保护和多任务环境下的隔离。 四、中断与异常处理...

    BDE_Installer_for_RAD_Studio_10.4

    5. **内存数据集(In-Memory Datasets)**:如 TDataset,允许在内存中操作数据,即使没有打开数据库连接。 在 RAD Studio 10.4 中使用 BDE 安装程序可能涉及到以下步骤: 1. **下载并解压**:获取 "BDE_Installer_...

    Ottawa Linux Symposium 2011论文集

    2011年OLS大会论文集涵盖了广泛的主题,包括系统内核优化、内存管理、存储技术、实时操作系统集成、增量检查点方法、多核系统调度、虚拟化技术、非法内存访问检测、性能监控与分析等。下面将详细介绍其中几篇具有...

Global site tag (gtag.js) - Google Analytics