Car*_*loS 8 iphone macos memory-management ios
有人可以告诉我,什么样的记忆是脏/居民,他们来自哪里?常驻内存与Mac OS的"有线内存"意味着相同吗?
这就是我所看到的Mac OS内存:
有线:这是指内核代码等.不应该从RAM中移出的内存.也称为常驻记忆.
共享:两个或多个进程共享的内存.这两个进程都会显示这个内存量,因此实际使用的内存量可能有点误导.
Real:这是task_info()报告的应用程序的"实际"内存使用情况 - 对当前进程具有的物理页面数量的粗略计数.(RSIZE)
私有:这是一个进程仅在它自己的内存中使用的内存.(RPRVT)
虚拟:映射到任何内容的进程中的地址空间总量 - 无论是变量或任何内容的任意大空间 - 它都不等于实际的VM使用.(VSIZE)
活动:当前标记为活动的内存,用于RAM.
非活动:"不活动的内存不再被使用并且已缓存到磁盘.它将保留在RAM中,直到另一个应用程序需要空间.如果您(或您的计算机的客户端)回来,将此信息留在RAM中对您有利.以后." - Mac OS X帮助
Free:没有任何数据的实际可用RAM量.
Car*_*loS 34
差不多一年了,我想出来了.
干净的记忆
clean memory are memories that can be recreated, on iOS it is memory of:
Also notice this situation: when your app link to a framework, the clean memory will increase by the size of the framework binary. But most of time, only part of binary is really loaded in physical memory.
dirty memory
All memory that is not clean memory is dirty memory, dirty memory can't be recreated by system.
When there is a memory pressure, system will unload some clean memory, when the memory is needed again, system will recreate them.
But for dirty memory, system can't unload them, and iOS has no swap mechanism, so dirty memory will always be kept in physical memory, till it reach a certain limit, then your App will be terminated and all memory for it is recycled by system.
virtual memory
virtual memory = clean memory + dirty memory.
Run Code Online (Sandbox Code Playgroud)
That means virtual memory is all the memory your App want.
resident memory
resident memory = dirty memory + clean memory that loaded in physical memory
Run Code Online (Sandbox Code Playgroud)
resident memory is the memory really loaded in your physical memory, it mean all the dirty memory and parts of your clean memory.
conclusion
At any time, this is always true:
virtual memory == (clean memory + dirty memory) > resident memory > dirty memory
Run Code Online (Sandbox Code Playgroud)
If you are worrying about the physical memory your App is taking(which is the key reason your App is terminated due to low memory), you should mainly focus on resident memory.
驻留内存是为您的应用分配的内存.脏内存是由于iOS中缺少分页系统而无法自动解除分配的驻留内存.我在http://liam.flookes.com/wp/2012/05/03/finding-ios-memory/上找到了这些信息.然后,对于您列出的内存类型,iOS中的驻留内存更接近真实或私有.根据我的理解,在iOS中你应该最关心的是脏内存,因为如果内存不足,它可以确定你的应用程序在后台挂起时是否会被杀死.