I've been reading about how garbage collection is a big problem when programming games using C#, Java, and the like - if you have a large amount of objects, the GC will run sporadically and scan through all the non-static objects you have, deleting them from memory as necessary. This can bog down your framerate or cause the game to crash if you've got a lot of objects.
From what I've read, the problem can be mitigated by statically declaring many objects during the game's initialization and storing them in an object pool (swapping out "active" and "inactive" static objects as needed so that the GC is never run). But I know it's also generally bad practice to use static objects (since it can become unclear what's what in memory, etc, etc) and I'm wondering if there's a middle ground.
So I guess I've really got 2 related questions:
- Is object pooling using static objects the best way to avoid GC?
- Under what circumstances should a Unity game be developed with some kind of GC avoidance in mind - when you're expecting to have 100 objects? 1000? 10000+?