When is memory allocated during instance creating or using new keyword for object creation?
问题 As I read somewhere, memory is allocated when instances are created and a space is allocated from the heap. If it is right than when and how much exactly memory is allocated during instances and objects creation? 回答1: Variables declared within a method are stored within the stack, while the actual objects are stored on the heap. Consider Integer a = new Integer(10); In this example, an object of type Integer is created on the heap and a reference (either 32 or 64bits) is returned and stored