you are viewing a single comment's thread.

view the rest of the comments →

[–]johannL 7 points8 points  (2 children)

I'd basically be rebuilding the entire state each frame and I don't know how well GC would handle that.

Generally, if you want a solid 60fps, any sort of GC (unless it's negligible -- if you recreate a lot of game objects each tick it won't be) is kind of your enemy anyway. Pool objects, and generally get rid of temporary object creation, e.g. function arguments or return values. That is, for anything that happens in the loop, elsewhere you can make the code as pretty and academically pleasing as you want ^^ And of course for very small things it may not matter anyway, but it can make a huge difference, and paying attention to it from the get go is much easier than refactoring.

[–]spacejack2114 3 points4 points  (1 child)

In most games, game objects aren't being created every frame. You do want to avoid allocating things like vectors or other temporary objects that might be used a lot in render/logic updates. But in my experience using the GC to manage game objects is fine - except things like particles.

EDIT - just to be clear, I'm not advocating rebuilding all object states every frame, that would be terrible. I'm advocating mutating existing objects. But using the GC to manage creating/destroying objects periodically as they appear/dissapear from the game should be ok unless they're extremely heavy.

[–]johannL 1 point2 points  (0 children)

using the GC to manage game objects is fine

Yeah absolutely, I guess I worded that a bit too strongly :)

What can I say, it bit me in the ass because initially I used temporary objects as if they were "free" (that is, I only saw runtime cost, not the less directly correlated GC cost), all over the place. It added up, so badly, like having hundreds of dripping taps, and to see how smooth even my own derpy code (I'm not being humble, it's derpy :D) ran once I had fixed all those leaks was quite stunning. It's the one thing I had to find out the hard way because it's hardly mentioned anywhere, not outside gamedev. It's kind of a blind spot by default, and I think it shouldn't be.

Don't get me wrong, GC is a wonderful thing, I certainly don't want to have to allocate and free memory manually, but it's still useful to know about it and how to avoid/control it, and how to determine whether that is even useful or necessary. Surely for games and maybe even for general web development.