java - Do uninitialized primitive instance variables use memory? -


In Java, is there a cost of memory to declare class-level instance variables without starting it? For example: what < i = 5; ?

Description: P>

I have a very large super-class, which are very different (not different superclasses ) Extensions of sub-classes do not use each primitive declared by some sub-class superclasses. Can I keep such priorities in an undisclosed form and can only start them in the necessary sub-orbit to save memory?

All the members defined in their classes are the default values, Therefore, they use memory

For example, each int will be started by default on 0 , and 4 < / Code> bytes will be captured.

For class members:

  int i;  

It is:

  int i = 0;  

What does the example variable say about:

If there is a field T in a field that is a frequency variable, then a new instance variable one As part of each newly created object of class T or any class, a default value has been created and started, which is a subclass of T (§8.1.4). After the completion of any necessary final form of the object (§ 12.6), for example, the existence exhausted effectively, when the area of ​​that object is no longer referenced.


Comments