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.
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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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.
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.