How do I find the size of an object in Java?
A: There is no direct management of the storage size of code that is held in memory by the Java Virtual Machine (JVM). The virtual machine manages the allocation and de-allocation of storage through an integral garbage collection system. The JVM keeps track of all object references and periodically disposes of de-referenced objects to free memory.
It is possible to check the overall memory use of a Java application with methods in the java.lang.Runtime class. The freeMemory() method returns the spare memory available to the runtime system, the totalMemory() method reports the total memory allocated to the virtual machine.
What part of memory is used for interfaces and abstract classes?
A: Interfaces and abstract classes are part of the application programming interface for the Java language, but are never instantiated in their own right when a Java program is run. Only objects are instantiated in the Java Runtime Environment (JRE) and held in a division of the program's memory allocation called the heap. Stack memory holds primitive values and the memory addresses of objects on the heap.
No comments:
Post a Comment