Take the following: int  myArray = new int  ; myArray = new int ; myArray = 6 ; myArray = 7 ; Do I understand correctly that there are two objects on the heap, those being the two arrays declared with the new? The myArray reference is on the stack then and the ints in myArray are also on on the heap but contained within the already allocated array object? Would the # of stack vs.heap objects differ if I was not using primatives? For example, Thing  myThingArray = new Thing  ; myThingArray = new Thing ; myThingArray = new Thing( 6 ) ; myThingArray = new Thing( 7 ) ; I assume that now I have two additional heap objects associated with the new Thing(s) referred to by myThingArray and myThingArray but still only one stack object.
posted 12 years ago
Hi Greg, Welcome to JavaRanch. Assuming that myArray and myThingArray are method locals and not instance variables, then I'd say you have a pretty good handle on what's going on.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher