Memory Usage and Garbage Collection in Java -


i have read many things memory usage in java.

my questions points towards game making. every frame call methods 500 times creating binary tree. each node call function , create 10 local variables.

  1. is better memory usage , or garbage collector create separate class holds needed variables, instantiate once , give every node reference object ?

if first question better, more "expensive" call .getsomething() separate object storing thing want in own object ?

thank all!

  1. as rule of thumb, less objects create, less pressure have on gc. if every "node" in application needs access same set of values, putting these values in 1 single object better allocate them each node on , on again.
  2. most not. jit compiler inline these calls if executed often.

as mentioned in comment of question, local primitive variables allocated on stack , not subject garbage collection. in cases, objects can allocated on stack due jit compiler's escape analysis technique.

generally speaking, if want find out how application behaves in terms of gc , allocations, should profile (e.g. java flight recorder's allocation profile) , take @ gc log. furthermore, should tune application based these results rather prematurely.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -