Why does garbage collection take so long (>10ms) sometimes.
<p>So I'm looking at two different projects in Unity in the profiler. One of them is listed to have &lt;10 mb of allocated gc, and it goes up at some rate, and then drops (garbage collection i guess) every 10 frames. The time for the drop occurs is so small that it doesn't affect anything. </p>

<p>Another project, shows in the profiler that i have 300-400 mb allocated gc. It goes up at 1/10th the rate above, but only seems to collect gc every 50-100 mb of allocated gc. This collection ends up taking longer than the frame time. </p>

<p>Is it taking longer because it's scanning through all of the variables in "allocated gc" for stuff that isn't needed any more? If so, how would I go about declaring a variable in such a way that it will not be scanned during garbage collection. I heard about "GC.KeepAlive" but I'm not sure if this would accomplish this. </p>

<p>It's a shame because I just did so much work reducing the amount of garbage produced at each frame (by using object pools), but gc is still happening, and still taking long. </p>