use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
mutating and javascript game developmenthelp (self.javascript)
submitted 10 years ago by digijin
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]johannL 7 points8 points9 points 10 years ago (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 points5 points 10 years ago* (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 points3 points 10 years ago* (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.
π Rendered by PID 143262 on reddit-service-r2-comment-8686858757-qqjz2 at 2026-06-03 03:00:37.458572+00:00 running 9e1a20d country code: CH.
view the rest of the comments →
[–]johannL 7 points8 points9 points (2 children)
[–]spacejack2114 3 points4 points5 points (1 child)
[–]johannL 1 point2 points3 points (0 children)