`
fonter
  • 浏览: 869173 次
  • 性别: 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.

分享到:
评论

相关推荐

    C_C++ 内存管理算法和实现 Memory Management Algorithms and Implementation in C_C++

    C_C++ 内存管理算法和实现 Memory Management Algorithms and Implementation in C_C++ C_C++ 内存管理算法和实现 Memory Management Algorithms and Implementation in C_C++ C_C++ 内存管理算法和实现 ...

    翻译《Memory Management in the Java HotSpot™ Virtual Machine》

    《Memory Management in the Java HotSpot™ Virtual Machine》一文深入探讨了Java HotSpot虚拟机中的内存管理机制,这是Java性能优化的关键领域。HotSpot虚拟机是Oracle JDK和JRE的一部分,以其高性能和优化能力而...

    Memory Management in the Java HotSpot Virtual Machine.pdf

    本文档提供了Java HotSpot虚拟机(JVM)中内存管理的广泛概述,特别是在Sun公司的Java 2平台标准版(J2SE)5.0版本的发布中。文档描述了可供使用的垃圾收集器(Garbage Collectors),给出了关于如何选择和配置收集...

    Memory Management: Algorithms and Implementation in C_C++

    “Memory Management: Algorithms and Implementation in C_C++.chm”文件可能包含了上述部分或全部知识点的详细讲解和实例,对于希望深入理解C/C++内存管理的开发者来说,是一份宝贵的参考资料。通过学习,开发者...

    Linux操作系统内存管理.pdf

    Linux操作系统内存管理 Linux操作系统的内存管理是计算机科学中一个重要的领域。本文将详细阐述Linux操作系统的内存管理机制,包括物理内存和虚拟内存的管理机制、地址映射机制、内存碎片和内存不连续的问题解决等...

    Memory Management: Algorithms and Implementation in C/C++

    C/C++实现的内存管理算法教材,CHM格式

    Understanding-Memory-Management-In-Spark-For-Fun-And-Profit.pdf

    由于提供的文件信息中包含了重复的标签和无关内容(WeChatOfficialAccounts:BigData321),我将忽略这些部分,并基于标题和描述中所提及的“Understanding-Memory-Management-In-Spark-For-Fun-And-Profit.pdf”和...

    Pro .NET Memory Management

    《Pro .NET Memory Management》这本书由Konrad Kokosa撰写,旨在帮助开发者更好地理解.NET内存管理的内部机制,从而提高代码质量、性能和可扩展性。 #### 二、.NET内存管理概述 .NET内存管理主要涉及两个方面:...

    Memory Management--Algorithms and Implementation in C/C++

    ### 内存管理:算法与C/C++中的实现 #### 内容概览 《内存管理:算法与C/C++中的实现》是一本深入探讨内存管理机制、策略及其在C/C++编程语言中具体实现的专业书籍。作者Bill Blunden通过本书系统地介绍了内存管理...

    memory management

    memory management 动态内存分配 FIFO算法

    Understanding Memory Resource Management in VMware® ESX™ Server

    更详细的资料可参阅“Memory Resource Management in VMware ESX Server”。 ESX利用高级资源管理策略计算每个虚拟机的目标内存分配,该分配基于当前系统负载以及虚拟机的设置参数(如份额、预留和限制)。计算出的...

    Virtual memory management ppt

    在“Virtual memory management ppt”中,主要探讨了虚拟内存管理的多个关键概念和策略。 11.1 引言:这部分介绍了虚拟内存管理的基本原理,包括替换策略和获取策略。替换策略是当内存满时,系统用来选择哪些页面...

    Aarch64 Kernel Memory Management.pptx

    aarch64 Linux Kernel Memory Management, aarch64 Linux Kernel Memory Management, aarch64 Linux Kernel Memory Management

    sdk2003文档 Memory Management

    sdk2003 win32 Memory Management sdk2003 win32 Memory Management

    Memory Management Simulator

    "Memory Management Simulator" 是一个模拟器,用于帮助理解并可视化内存管理的过程。这个模拟器利用了Java Swing库来构建用户界面,使得用户能够交互地探索内存分配和回收的机制。 在Java中,内存分为堆(Heap)和...

    操作系统memory management

    Goals of memory management  To provide a convenient abstraction for programming  To allocate scarce memory resources among competing processes to maximize performance with minimal overhead

    c模拟内存管理.rar_C 内存_c 内存模拟_memorymanagement_操作系统_模拟内存管理

    一个用C写的内存管理系统,模拟操作系统内存

    Memory management(内存管理)

    ### 内存管理在JavaScript开发中的重要性及内存泄漏检测 #### 一、引言 在现代Web开发中,JavaScript已成为构建复杂应用的核心语言之一。然而,随着应用程序规模的不断增大,有效地管理内存成为了保证应用性能和...

    C++ Memory Management Innovation

    ### C++内存管理创新:GC Allocator #### 引言 在C++编程中,内存管理一直是一个关键且复杂的任务。大多数C++程序员不得不手动管理内存,包括分配和释放内存资源,这不仅耗时而且容易出错。随着软件工程的发展,...

Global site tag (gtag.js) - Google Analytics