From the course: Java Memory Management: Values and References
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Garbage collection - Java Tutorial
From the course: Java Memory Management: Values and References
Garbage collection
- [Instructor] I have mentioned garbage collection quite a few times already. When objects are created in the heap memory they start taking up space, clearly. And at some point we no longer need the objects in our heap memory, and they can be removed. Garbage collection is the removal process of objects on the heap. So, how to start the garbage collector? It's actually quite an elaborate topic that's definitely worth understanding at a very detailed level. But in this course we'll only be covering it briefly. So, you may wonder, when does garbage collection take place? Well, you don't know. Although they don't typically say, okay, but how can I evoke it? Well, you could call system.GC. This is a method. This is merely a suggestion to the JVM that it should start the garbage collection process. And actually, you can not really force the JVM to start garbage collection. So, this is not something that you get to decide as a developer. The JVM will decide when garbage collection should…