简体   繁体   中英

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. 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. 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. 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

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). 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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