Is memory allocated for unused fields in Java?
•
Java
I want to know how memory allocation works in Java
I have a class duck with two instance variables int size and string name These variables are initialized If I do not instantiate this class, is the memory of these variables allocated on the heap at runtime?
Thank you, gene
Solution
Several possible situations:
>If you are not in class, the class itself is not loaded into the class loader. > If you are using the course, but not instantiating it, then the instance variable does not occupy memory because there is no instance to start. > If you are using a course and use the object class as its instance, then the instance variable uses memory for each instance, whether you use these values or not
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码