What is a memory leak in Java?
A memory leak in Java occurs when objects are no longer used but are still referenced, preventing the garbage collector from reclaiming memory.
Exactly! Memory leaks occur when unreachable objects are still referenced, causing memory to be consumed unnecessarily.
Can you explain how the garbage collector works in relation to unreachable objects and how it detects memory leaks?