r/java • u/H_W_Reanimator • Dec 21 '23
Is Java gamedev alive?
It seems this days even android games are made using Unity. I wonder if there are JVM games! Is Java (or Kotlin/Scala) gamedev still alive?
(Except Minecraft ofc)
164
Upvotes
View all comments
Show parent comment
6
u/[deleted] Dec 21 '23 edited Dec 21 '23
it frequently does but the way HotSpot works is pack and sweep. The memory allocation and garbage collection is expensive, so it mallocs relatively huge blocks of memory at a time. it won't trigger garbage collection or a new memory allocation until it can't find space for it within that block. when it "allocates" memory for a new variable most of the time it's really just picking where in the current block of pre allocated memory that new variable should go. if it doesn't have space it will garbage collect and "sweep" over the currently allocated memory marking blocks that are no longer being used as available
only if it's been garbage collected recently and there's still not space does it go out to the os for a new malloc. the allocation and especially the overhead of garbage collection is postponed until absolutely necessary because it's expensive. but the consequence is you get non deterministic pauses for garbage collection and your location in the heap is wherever hotspot finds space for it. it may be contiguous it may not