Garbage Collection Flashcards

1
Q

What is garbage collection?

A

The internal mechanism to reclaim the memory of unused objects at runtime. Also known as automatic memory management.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why does java provide garbage collection?

A

Since memory management is provided by the JVM in Java, after some time the JVM may run low on memory. The JVM must then free memory from unused objects. To help with the process of reclaiming memory, Java provides automatic memory management.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the purpose of .gc( ) ?

A

Java provides two methods System.gc( ) and Runtime.gc( ) to explicitly send a request for Garbage Collection to run.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How does garbage collection work?

A

When the JVM is low on memory, GC process finds the unused objects that are not referenced by other objects. This objects are then cleaned up by the Garbage Collector daemon in JVM.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

When does an object become eligible for Garbage Collection?

A

If the object is not reachable, e.g an object/instance that cannot be reached by a live thread. A set of circularly referenced instances that cannot be reached by any other instance outside that set.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What kind of process is the Garbage collector thread?

A

A daemon process in JVM. An internal process that keeps checking memory usage and cleans up the memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly