什么是iOS的常驻和脏记忆?

时间:2021-07-20 05:32:00

Can some one please tell me, what kind of memory is dirty/resident, and where do they come from? Does resident memory means the same with "wired memory" of Mac OS?

有人可以告诉我,什么样的记忆是脏/居民,他们来自哪里?驻留内存与Mac OS的“有线内存”意味着相同吗?

this is what I saw about Mac OS memory:

这就是我所看到的Mac OS内存:

Wired : This refers to kernel code and such. Memory that should not ever be moved out of the RAM. Also know as resident memory.

有线:​​这是指内核代码等。不应该从RAM中移出的内存。也称为常驻记忆。

Shared : Memory that is shared between two or more processes. Both processes would show this amount of memory so it can be a bit misleading as to how much memory is actually in use.

共享:两个或多个进程共享的内存。这两个进程都会显示这个内存量,因此实际使用的内存量可能有点误导。

Real : This is the "real" memory usage for an application as reported by task_info() - a rough count of the number of physical pages that the current process has. (RSIZE)

Real:这是task_info()报告的应用程序的“实际”内存使用情况 - 对当前进程具有的物理页面数量的粗略计数。 (RSIZE)

Private : This is memory that a process is using solely on it's own that is used in Resident memory. (RPRVT)

私有:这是一个进程仅在它自己的内存中使用的内存。 (RPRVT)

Virtual : The total amount of address space in the process that's mapped to anything - whether that's an arbitrarily large space for variables or anything - it does not equate to actual VM use. (VSIZE)

虚拟:映射到任何内容的进程中的地址空间总量 - 无论是变量或任何内容的任意大空间 - 它都不等于实际的VM使用。 (VSIZE)

Active : Memory currently labelled as active and is used RAM.

活动:当前标记为活动的内存,用于RAM。

Inactive : "Inactive memory is no longer being used and has been cached to disk. It will remain in RAM until another application needs the space. Leaving this information in RAM is to your advantage if you (or a client of your computer) come back to it later." - Mac OS X Help

非活动:“不活动的内存不再被使用并且已缓存到磁盘。它将保留在RAM中,直到另一个应用程序需要空间。如果您(或您的计算机的客户端)返回,将此信息留在RAM中对您有利。以后。“ - Mac OS X帮助

Free : The amount of RAM actually available without any data.

免费:实际可用的RAM量,没有任何数据。

2 个解决方案

#1


27  

It's almost a year and I figured it out.

差不多一年了,我想出来了。

clean memory

clean memory are memories that can be recreated, on iOS it is memory of:

干净的记忆是可以重新创建的记忆,在iOS上它是以下内存:

  • system framework
  • binary executable of your app
  • 您应用的二进制可执行文件

  • memory mapped files
  • 内存映射文件

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.

但对于脏内存,系统无法卸载它们,并且iOS没有交换机制,因此脏内存将始终保存在物理内存中,直到达到一定限度,然后您的应用程序将被终止并且所有内存都将被回收按系统。

virtual memory

virtual memory = clean memory + dirty memory.

That means virtual memory is all the memory your App want.

这意味着虚拟内存是您的应用程序所需的所有内存。

resident memory

resident memory = dirty memory + clean memory that loaded in physical memory

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

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.

如果您担心应用程序正在使用的物理内存(这是因内存不足而导致应用程序终止的关键原因),您应该主要关注驻留内存。

#2


7  

Resident memory is the memory that is allocated for your app. Dirty memory is the resident memory that cannot be automatically deallocated due to the lack of a paging system in iOS. I found this information at http://liam.flookes.com/wp/2012/05/03/finding-ios-memory/. Then for the types of memory that you listed, resident memory in iOS is closer to real or private. From my understanding, it is the dirty memory that you should be most concerned about in iOS as it can determine if your app gets killed when suspended in the background if there is a low-memory condition.

驻留内存是为您的应用分配的内存。脏内存是由于iOS中缺少分页系统而无法自动解除分配的驻留内存。我在http://liam.flookes.com/wp/2012/05/03/finding-ios-memory/上找到了这些信息。然后,对于您列出的内存类型,iOS中的驻留内存更接近真实或私有。根据我的理解,在iOS中你应该最关心的是脏内存,因为如果内存不足,它可以确定你的应用程序在后台挂起时是否会被杀死。

#1


27  

It's almost a year and I figured it out.

差不多一年了,我想出来了。

clean memory

clean memory are memories that can be recreated, on iOS it is memory of:

干净的记忆是可以重新创建的记忆,在iOS上它是以下内存:

  • system framework
  • binary executable of your app
  • 您应用的二进制可执行文件

  • memory mapped files
  • 内存映射文件

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.

但对于脏内存,系统无法卸载它们,并且iOS没有交换机制,因此脏内存将始终保存在物理内存中,直到达到一定限度,然后您的应用程序将被终止并且所有内存都将被回收按系统。

virtual memory

virtual memory = clean memory + dirty memory.

That means virtual memory is all the memory your App want.

这意味着虚拟内存是您的应用程序所需的所有内存。

resident memory

resident memory = dirty memory + clean memory that loaded in physical memory

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

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.

如果您担心应用程序正在使用的物理内存(这是因内存不足而导致应用程序终止的关键原因),您应该主要关注驻留内存。

#2


7  

Resident memory is the memory that is allocated for your app. Dirty memory is the resident memory that cannot be automatically deallocated due to the lack of a paging system in iOS. I found this information at http://liam.flookes.com/wp/2012/05/03/finding-ios-memory/. Then for the types of memory that you listed, resident memory in iOS is closer to real or private. From my understanding, it is the dirty memory that you should be most concerned about in iOS as it can determine if your app gets killed when suspended in the background if there is a low-memory condition.

驻留内存是为您的应用分配的内存。脏内存是由于iOS中缺少分页系统而无法自动解除分配的驻留内存。我在http://liam.flookes.com/wp/2012/05/03/finding-ios-memory/上找到了这些信息。然后,对于您列出的内存类型,iOS中的驻留内存更接近真实或私有。根据我的理解,在iOS中你应该最关心的是脏内存,因为如果内存不足,它可以确定你的应用程序在后台挂起时是否会被杀死。