Q. What is the purpose of garbage collection in Java, and when is it used ?
To identify and discard those objects that are no longer needed by the application, in order to reuse the resources.
Q. What the functions System.gc() and Runtime.gc() methods do ?
- These are used as a hint to the JVM, in order to start a garbage collection.
- It is up to the JVM to start the garbage collection immediately or later in time.
Q. When is the finalize() called ?
- finalize() is called by the garbage collector, just before releasing the object’s memory.
- used to release resources held by the object.
Q. If an object reference is set to null, will the Garbage Collector immediately free the memory held by that object ?
No, the object will be available for garbage collection.
It is up to the JVM to start the garbage collection immediately or later in time.
Q. What is the structure of Java heap ?
- The JVM has a heap which is a runtime data area from which memory for all class instances and arrays is allocated.
- Heap memory is created at the JVM start-up and consists of live and dead objects.
- Live objects are accessible by the application and Dead objects are those which will never be accessible by the application, but have not been collected by the garbage collector yet.
Q. When does an Object becomes eligible for Garbage collection in Java ?
When it becomes unreachable to the program in which it is currently used
Q. Does Garbage collection occur in permanent generation space in JVM ?
Garbage Collection does occur in PermGen space and if PermGen space is full or cross a threshold, it can trigger a full garbage collection.
This is the reason why correct sizing of PermGen space is important to avoid frequent full garbage collections.
When it becomes unreachable to the program in which it is currently used
Q. Does Garbage collection occur in permanent generation space in JVM ?
Garbage Collection does occur in PermGen space and if PermGen space is full or cross a threshold, it can trigger a full garbage collection.
This is the reason why correct sizing of PermGen space is important to avoid frequent full garbage collections.
No comments:
Post a Comment
Note: only a member of this blog may post a comment.