短期对象对象

2023-09-04 08:16:05 作者:Tdliche(致命)

什么是产生大量的临时对象(即对中期业绩)认为,英年早逝的开销(从来没有晋升到下一代垃圾收集间隔期间)?我假设的新的操作是非常便宜的,因为它实际上只是一个指针增量。然而,什么是处理这个临时的窝?

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"?

推荐答案

不是很多 - 垃圾收集器是非常快的gen0。它还曲调本身,调整gen0视的大小多少管理各个它去的时间来收集。 (如果它成功地收集了很多,这将减少gen0收集较早接下来的时间,反之亦然的大小。)

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

最终的考验是如何的您的应用,虽然执行。性能监视器是非常方便的位置,显示出有多少时间被花费在GC,有多少藏品已经有每一代人等。

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.