are java primitives garbage collected

前端 未结 3 1908
Happy的楠姐
Happy的楠姐 2020-12-03 17:45

If I declare an int (or any primitive type) within a method in Java, is that memory freed the moment the function returns, or does it have to hang around until the garbage c

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-03 18:12

    Primitives are allocated on the stack, so their memory is freed the moment the function returns.

提交回复
热议问题