void someMethod() {
byte[] array = { 0, 0 };
}
Will this array be stored in heap or on the stack?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can think of it as always going on the heap.
I believe some smart VMs are able to stack-allocate objects if they can detect it’s safe – but conceptually it’s on the heap. In particular, all array types are reference types (even if the element type is primitive), so the
arrayvariable (which is on the stack) is just a reference to an object, and objects normally go on the heap.In particular, imagine a small change:
If the array were allocated on the stack, what would the returned reference have to refer to?