简体   繁体   English

我的过程内存恒定吗?

[英]Is my process memory constant?

It is an academic question. 这是一个学术问题。 If I have a constant number of variables, objects, etc. And we assume that GC will not kick in, and there is no bottlenecks. 如果我有恒定数量的变量,对象等,并且我们假定GC将不会启动,也不会出现瓶颈。 Could some other factor force my application memory to fluctuate? 其他因素是否可以迫使我的应用程序内存波动? In such a scenario would allocated by my process memory stay constant? 在这种情况下,由我的进程分配的内存将保持不变吗?

You could call unmanaged functions using interop which modify the amount of available memory. 您可以使用互操作来调用非托管函数,该互操作会修改可用内存量。 Also the JIT compiler might kick in at any moment to convert the IL to machine code and probably consume memory. 而且,JIT编译器可能会随时启动以将IL转换为机器代码,并可能消耗内存。 Also assuming that GC won't kick in is not something which you can actually assume if you use .NET, so any conclusion you draw starting from a wrong assumption will be wrong. 另外, 假设如果您使用.NET,则不能假定GC不会启动,因此从错误的假设开始得出的任何结论都是错误的。 So to answer your question you cannot assume that memory will stay constant. 因此,要回答您的问题,您不能假设内存将保持不变。

Your scenario is contrived and unrealistic: 您的方案是人为的,不现实的:

And we assume that GC will not kick in 我们假设GC将不会启动

Well, it will. 好吧,会的。 Your application may take different paths during its execution. 您的应用程序在执行过程中可能采用不同的路径。 If it does, than the state can be different from time to time, references to objects on the heap may be kept around longer, etc. I don't really see the purpose of this question. 如果确实如此,则状态可能会不时有所不同,对堆上对象的引用可能会保留更长的时间,等等。我真的看不到这个问题的目的。

It is possible, as in the sort of case mentioned in the question at How do these people avoid creating any garbage? 就像在这些人如何避免产生任何垃圾的问题中提到的那种情况那样,这是可能的 to put a system into a state where it is working with a constant memory set and no GC is happening (because nothing is allocated that will need it to collect and it dies away to nothing). 使系统处于使用恒定内存集且不发生任何GC的状态(因为没有分配任何东西需要收集它,并且死掉了)。 The article linked to even has a practical (but highly specialised) case. 链接到的文章甚至有一个实际的(但高度专业化的)案例。

Note that they have a large number of methods and classes they don't use that most of us would use every day. 请注意,它们有很多方法和类,它们不使用我们大多数人每天都会使用的方法和类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM