What is the purpose of garbage collection in Java, and when it is used? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is the purpose of garbage collection in Java, and when it is used?

17th Oct 2019, 5:55 PM
Neba Emmanuel
Neba Emmanuel - avatar
2 Answers
+ 3
Garbage collection is used if your program is taking up way too much memory. It deletes data, which won't be used anymore.
17th Oct 2019, 5:59 PM
Jannik Müller
Jannik Müller - avatar
+ 3
In a low language like C, you have to require areas in memory and release them by hand, when you're done. You'll have to mess around with pointers, and a lot of things can go wrong. Higher languages like Java have this process automatized. The whole procedure of requiring and releasing the memory happens in the background without you even knowing.
17th Oct 2019, 6:24 PM
HonFu
HonFu - avatar