How are static arrays stored in Java memory?

前端 未结 7 1938
名媛妹妹
名媛妹妹 2021-02-18 21:33

So in a language like C, memory is separated into 5 different parts: OS Kernel, text segment, static memory, dynamic memory, and the stack. Something like this:

7条回答
  •  爱一瞬间的悲伤
    2021-02-18 22:12

    In java any time you use the word new, memory for that object is allocated on the heap and a reference is returned. This is also true for arrays. The int[] a is just the reference to new int[1]. When you do new int[2], a new array is allocated and pointed to a. The old array will be garbage collected when needed.

提交回复
热议问题