Difference between revisions of "Thread:Talk:XanderCat/Garbage Collection and Skipped Turns/reply (10)"

From Robowiki
Jump to navigation Jump to search
 
(No difference)

Latest revision as of 16:28, 4 April 2013

Arrays are objects in java:

public void func() {

  int[] myArray; // myArray variable on the stack
  myArray = new int[5]; // Array object allocated on heap, referenced by myArray variable on the stack

}

Note that member variables of objects are obviously going to take up memory on the heap not the stack - eg if you have 30 primitive member variables (ints, doubles etc) of a class and call new on that class, it will take up more memory allocation than a class that has 1 primitive member variable.

However allocating 30 local primitive variables during a function call allocates those primitive types on the stack alongside you local member reference variables.