Search code examples
javaobjectgarbage

Garbage Collection works automatically or manually?


I want to ask if garbage collector automatically deletes unused objects in a Java program or it should be manually done by assigning an object to null?


Solution

  • From here

    In a programming language like C, allocating and deallocating memory is a manual process. In Java, process of deallocating memory is handled automatically by the garbage collector.

    I'd suggest you reading the full article. You will have a good grasp of how GC works in Java. HTH.