Memory Management Quiz - Languages Java
Free practice quiz: Memory Management (Languages Java). 52 multiple-choice questions with answers and explanations. Play online, no sign-up needed.
Play all 52 questions freeSample questions
In Java, which garbage collector is primarily designed for server-side applications, offering high throughput and low pause times?
- Serial Garbage Collector
- Parallel Garbage Collector
- G1 (Garbage-First) Garbage Collector
- CMS (Concurrent Mark Sweep) Garbage Collector
Show answer
Answer: C. G1 (Garbage-First) Garbage Collector
The G1 Garbage Collector is optimized for server-side applications, aiming to balance throughput with predictable pause times by dividing the heap into regions and collecting garbage from regions with the most garbage first.
Which of the following is NOT a type of reference in Java that affects garbage collection?
- Strong reference
- Weak reference
- Soft reference
- Abstract reference
Show answer
Answer: D. Abstract reference
Java has Strong, Soft, Weak, and Phantom references. 'Abstract reference' is not a distinct reference type in this context. Each type influences when an object can be garbage collected.
What does the JVM option `-XX:+UseG1GC` do?
- Enables the Serial Garbage Collector
- Enables the Parallel Garbage Collector
- Enables the G1 (Garbage-First) Garbage Collector
- Disables garbage collection
Show answer
Answer: C. Enables the G1 (Garbage-First) Garbage Collector
This JVM flag explicitly instructs the JVM to use the G1 garbage collector.
Which statement best describes the behavior of the 'copying' garbage collection algorithm?
- It identifies all garbage objects and then frees their memory.
- It divides the heap into two spaces: 'from-space' and 'to-space'. Live objects are copied from 'from-space' to 'to-space' during collection.
- It compacts the memory by moving objects to fill gaps left by garbage.
- It is primarily used for the old generation.
Show answer
Answer: B. It divides the heap into two spaces: 'from-space' and 'to-space'. Live objects are copied from 'from-space' to 'to-space' during collection.
The copying algorithm is efficient for collecting short-lived objects. It minimizes fragmentation by moving all live objects to one space, leaving the other space completely free for the next allocation cycle.
What is the primary benefit of using generational garbage collection?
- It simplifies memory allocation for all object types.
- It reduces the frequency of full heap scans by leveraging the 'weak generational hypothesis' (most objects die young).
- It guarantees no 'stop-the-world' pauses.
- It eliminates the need for heap dumps.
Show answer
Answer: B. It reduces the frequency of full heap scans by leveraging the 'weak generational hypothesis' (most objects die young).
Generational GC divides the heap into generations (young and old). Since most objects are short-lived and die in the young generation, frequent, quick collections there are efficient. Objects surviving these collections are promoted to the old generation, which is scanned less frequently.