Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Object creation on Array Initialisation

 
Neha Daga
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


the code above creates 3 objects on heap, one array and two thread objects. and the array will hold reference to these object in corresponding index position.
That's fine.


here only one object is created on heap. what about the primitive values that are being assigned to array, where are they stored???

is it the bit pattern of those values that is stored in the corresponding index position's allocated memory.
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here only one object is created on heap. what about the primitive values that are being assigned to array, where are they stored???

The values are stored in the array itself. Each element in the array will store the int value. When you create an array of references (like your first example), then each element in the array stores the reference variable (and the reference variables points to an objects on the heap), in case of a primitive value, the actual value is stored in the array...
 
Jeevan Reddy
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankit Garg wrote:
here only one object is created on heap. what about the primitive values that are being assigned to array, where are they stored???

The values are stored in the array itself. Each element in the array will store the int value. When you create an array of references (like your first example), then each element in the array stores the reference variable (and the reference variables points to an objects on the heap), in case of a primitive value, the actual value is stored in the array...


Thanks for the explanation
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic