Explain how the Java Virtual Machine (JVM) manages memory, and describe the difference between garbage collection algorithms.