xcode 与虚拟内存相关的“脏”和“常驻”是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5176074/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 20:22:06  来源:igfitidea点击:

What do "Dirty" and "Resident" mean in relation to Virtual Memory?

iphoneobjective-cxcodeiosinstruments

提问by m0rtimer

I dropped out of the CS program at my university... So, can someone who has a full understanding of Computer Science please tell me: what is the meaning of Dirty and Resident, as relates to Virtual Memory?And, for bonus points, what the heck is Virtual Memory anyway? I am using the Allocations/VM Tracker tool in Instruments to analyze an iOS app.

我在我的大学中退学了 CS 课程...所以,请对计算机科学有充分了解的人告诉我:Dirty 和 Resident 与虚拟内存相关的含义是什么?而且,对于奖励积分,虚拟内存到底是什么?我在 Instruments 中使用 Allocations/VM Tracker 工具来分析 iOS 应用程序。

*Hint- try to explain as if you were talking to an 8-year old kid or a complete imbecile. Thanks guys.

*提示- 试着解释,好像你在和一个 8 岁的孩子或一个完全低能的人说话。谢谢你们。

回答by blueberryfields

"Dirty memory" is memory which has been changed somehow - that's memory which the garbage collector has to look at, and then decide what to do with it. Depending on how you build your data structures, you could cause the garbage collector to mark a lot of memory as dirty, having each garbage collection cycle take longer than required. Keeping this number low means your program will run faster, and will be less likely to experience noticeable garbage collection pauses. For most people, this is not really a concern.

“脏内存”是以某种方式改变的内存 - 垃圾收集器必须查看的内存,然后决定如何处理它。根据您构建数据结构的方式,您可能会导致垃圾收集器将大量内存标记为脏,从而使每个垃圾收集周期花费的时间比所需的要长。保持这个数字较低意味着您的程序将运行得更快,并且不太可能遇到明显的垃圾收集暂停。对于大多数人来说,这并不是真正的问题。

"Resident memory" is memory which is currently loaded into RAM - memory which is actually being used. While your application may require that a lot of different items be tracked in memory, it may only require a small subset be accessible at any point in time. Keeping this number low means your application has lower loading times, plays well with others, and reduces the risk you'll run out of memory and crash as your application is running. This is probably the number you should be paying attention to, most of the time.

“常驻内存”是当前加载到 RAM 中的内存 - 实际正在使用的内存。虽然您的应用程序可能需要在内存中跟踪许多不同的项目,但它可能只需要在任何时间点都可以访问一小部分。保持这个数字较低意味着您的应用程序加载时间更短,与其他应用程序兼容,并降低您在应用程序运行时耗尽内存和崩溃的风险。大多数时候,这可能是您应该注意的数字。

"Virtual memory" is the total amount of data that your application is keeping track of at any point in time. This number is different from what is in active use (what's being used is marked as "Resident memory") - the system will keep data that's tracked but not used by your application somewhere other than actual memory. It might, for example, save it to disk.

“虚拟内存”是您的应用程序在任何时间点跟踪的数据总量。这个数字与正在使用的数字不同(正在使用的数字被标记为“驻留内存”)——系统会将被跟踪但未被您的应用程序使用的数据保存在实际内存之外的其他地方。例如,它可能会将其保存到磁盘。

回答by Robert

WWDC 2013 - 410 Fixing Memory IssuesExplains this nicely. Well worth a watch since it also explains some of the practical implications of dirty, resident and virtual memory.

WWDC 2013 - 410 Fixing Memory Issues很好地解释了这一点。非常值得一看,因为它还解释了脏内存、常驻内存和虚拟内存的一些实际含义。