DEV Community

Discussion on: Garbage Collector: The Desirable Aspect of Java

Collapse
 
mainrs profile image
mainrs

I wouldn’t call it “reducing the changes of having memory leaks”. Java just gets rid of the manual memory management for you. Garbage collection does not magically remove memory leaks. It just removes one incident.

However, it does also introduce new problems. What if two objects reference each other? But you don’t reference one of them. A “basic” implementation wouldn’t collect them since they each have a valid reference and seem to get used. Cyclic dependencies are a GC’s nightmare.

Collapse
 
haytamkh7 profile image
haytam_7 • Edited

The garbage collection reclaims the used resources that are no longer in use. It's like saying "When there are no references to an object, the object then is ready to be collected".
Memory that is not automatically reclaimed usually leads to a memory leaks, a situation that is less likely to happen in Java.