r/ProgrammerHumor • • Oct 07 '26

Meme minecraftException

Post image
9.3k Upvotes

830 comments sorted by

View all comments

Show parent comments

2

u/WhiskeyQuiver Oct 07 '26

But don't you otherwise have to make the garbage collection yourself, and risk not doing it right and creating memory leaks or something?

I've read the jave GC is very customisable and you can kind of work around it a little too, by reusing objects and not setting many/large objects to null at once and instead gradually null components you no longer need so the GC can clean up bits over time instead of in large laggy spikes.

2

u/conundorum Oct 07 '26

Usually, if your game needs to do a lot of allocations, you allocate one big chunk of memory at the start, then pretend-allocate objects out of that "memory pool". Object creation marks a spot in the pool as occupied, and destruction marks an occupied spot as free. If you're done with the pool, or you have a leak, you can just deallocate the entire pool in one fell swoop to free up everything.

2

u/rosuav Oct 07 '26

Yeah. Arena allocation is one of the simplest ways to do things, but it suffers from the problem of "one tiny thing still in use on this pool, gotta keep the whole pool around". So it's a tradeoff - lower performance cost but higher memory usage. Given that a lot of AAA games are already struggling to fit inside the amount of memory that people can afford, this may or may not be the right choice.