What is the overhead of generating a lot of temporary objects (i.e. for interim results) that ‘die young’ (never promoted to the next generation during a garbage collection interval)? I’m assuming that the ‘new’ operation is very cheap, as it is really just a pointer increment. However, what are the hidden costs of dealing with this temporary ‘litter’?
Share
Not a lot – the garbage collector is very fast for gen0. It also tunes itself, adjusting the size of gen0 depending on how much it manages to collect each time it goes. (If it’s managed to collect a lot, it will reduce the size of gen0 to collect earlier next time, and vice versa.)
The ultimate test is how your application performs though. Perfmon is very handy here, showing how much time has been spent in GC, how many collections there have been of each generation etc.