tags:

views:

53

answers:

3

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 proccess memory stay constant?

+1  A: 

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.

Darin Dimitrov
+1  A: 

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.

Ed Swangren
If there is enogh free memory on the system, why should GC start?
kofucii
@kofucii: the GC works with different dataset sizes. The most recently allocated data is fitted into a very small buffer, and when that runs out, the GC runs, cleaning up some allocations, and moving others to the larger heap for older objects. So even if you have plenty of memory, the .NET GC will run once you've allocated a fairly small amount of memory, regardless of how much total memory you have.
jalf
It's still a good question though. This is just the policy that the .NET GC follows. :)
jalf
@kofucii, what @jalf says holds true, because unless the GC cleans out memory, then lots of paging would mean that that "enough free memory" was still inefficient to use. However, it is possible have no more heap allocations happen, and GC to cease, but not desirable 99.999% of the times.
Jon Hanna
+1  A: 

It is possible, as in the sort of case mentioned in the question at http://stackoverflow.com/questions/3430342/how-do-these-guys-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.

Jon Hanna