3 ms·
Very nice example contains only the code it needs to explain the concept. Are there any languages that gc every tick?
by mentos 11y ago
Very nice example contains only the code it needs to explain the concept.
Are there any languages that gc every tick?
- munificent 11y agoNot that I know of. There are a bunch of games that use "arena allocators" or "per-frame allocators". Often, the game engine creates a bunch of objects during a frame of gameplay that it knows won't be needed once that frame is done. There's a clever strategy for managing that. When the game starts up, you allocate a big block of memory, the arena, and then set a pointer to the beginning of it. To allocate an object, you just increment the pointer by the size of the object being allocated and return the previous value. In other words, you just hand out some bytes and move the pointer just past them. When the frame is done, to "free" all of those objects... just reset the pointer. Done. But, to your original question, it's almost always a bad idea to run your GC every tick or some other high frequency like that. GCs spend a certain amount of time visiting objects that are still in use. Doing that work over and over and over again burns tons of cycles for no point. To get the best overall performance, you want to do as few GCs as possible to minimize that redundant work. The problem then is that when you wait a long time, you end up having to a big, slow GC and long pauses like that are a problem. Incremental and concurrent GCs avoid long pauses and give you smoother results, at the expense of slightly lower overall performance. They get better latency but worse throughput.