0% found this document useful (0 votes)
118 views2 pages

Garbage Collectors

Uploaded by

sagartribhuvan21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
118 views2 pages

Garbage Collectors

Uploaded by

sagartribhuvan21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 2
Java Interview Questions 12/30 Chapter 5 Garbage Collectors 5.1 What is the purpose of garbage collection in Java, and when is it used ? ‘The purpose of garbage collection is to identify and discard those objects that are no longer needed by the application, in order for the resources to be reclaimed and reused. 5.2 What does System.ge() and Runtime.ge() methods do ? ‘These methods can be used as a hint to the IVM, in order to star a garbage collection. However, this itis up to the Java Virtual Machine (TVM) to start the garbage collection immediately or later in time. 5.3. When is the finalize() called ? What is the purpose of finalization ? ‘The finalize method is called by the garbage collector, just before releasing the object’s memory. Its normally advised to release resources held by the object inside the finalize method. 5.4. Itan 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 in the next cycle of the garbage collector, 5.5 Whatis structure of Java Heap ? What is Perm Gen space Heap ? ‘The JVM has a heap that is the runtime data area from which memory forall class instances and arrays is allocated, It is ereated al the JVM start-up. Heap memory for objects is reclaimed by an automatic memory management system which is known as a garbage collector. Heap memory consists of live and dead objects. Live objects are accessible by the application and will not, be a subject of garbage collection. Dead objects are those which will never be accessible by the application, but have not been collected by the garbage collector yet. Such objects occupy the heap memory space until they are eventually collected by the garbage collector, Java Interview Questions 13/30 5.6 What is the difference between Serial and Throughput Garbage collector ? The throughput garbage collector uses a parallel version of the young generation collector and is meant to be used with applica tions that have medium to large data sets. On the other hand, the serial collector is usually adequate for most small applications (hose requiring heaps of up to approximately IOOMB on modern processors) 5.7 When does an Object becomes eligible for Garbage collection in Java ? A Java object is subject to garbage collection when it becomes unreachable to the program in which itis currently used, 5.8 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, If you look carefully at the output of the garbage collector, you will find that PermGen space is also garbage collected. This is the reason why correct sizing of PermGen space is important to avoid frequent full garbage collections. Also check our article Java 8: PermGen to Metaspace.

You might also like