Quiz: Garbage Collection

To View Tricks: Login Required

Number of Questions: 13

Question: 1 -

Which of the below is not a memory leak solution?

Options:
  1. GC parameter tuning

  2. JVM parameter tuning

  3. Process restart

  4. Code changes

  5. Answer:

    Process restart

    Solution:

    Process restart is not a permanent fix to memory leak problem. The problem will resurge again.


Question: 2 -

What is -Xms and -Xmx while starting jvm?

Options:
  1. Initial memory

  2. Initial; Maximum memory

  3. Maximum; Initial memory

  4. Maximum memory

  5. Answer:

    Initial; Maximum memory

    Solution:

    JVM will be started with Xms amount of memory and will be able to use a maximum of Xmx amount of memory. java -Xmx2048m -Xms256m.


Question: 3 -

Which of the below is not a Java Profiler?

Options:
  1. JConsole

  2. JProfiler

  3. Eclipse Profiler

  4. JVM

  5. Answer:

    JVM

    Solution:

    Memory leak is like holding a strong reference to an object although it would never be needed anymore. Objects that are reachable but not live are considered memory leaks. Various tools help us to identify memory leaks.


Question: 4 -

What allows the programmer to destroy an object x?

Options:
  1. Runtime.getRuntime().gc()

  2. Only the garbage collection system can destroy an object

  3. x.delete()

  4. x.finalize()

  5. Answer:

    Only the garbage collection system can destroy an object

    Solution:

    When an object is no longer referenced, it may be reclaimed by the garbage collector. If an object declares a finalizer, the finalizer is executed before the object is reclaimed to give the object a last chance to clean up resources that would not otherwise be released. When a class is no longer needed, it may be unloaded.


Question: 5 -

How to get prints of shared object memory maps or heap memory maps for a given process?

Options:
  1. memorypath

  2. memorymap

  3. jvmmap

  4. jmap

  5. Answer:

    jmap

    Solution:

    We can use jmap as jmap -J-d64 -heap pid.