• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

The Java Garbage Collector

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you please explain to me in short what tha Garbage Collector does and why is it useful ?
Thank you
 
Ranch Hand
Posts: 148
Hibernate Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

GC is one that do automatically recollects the memory if no valid reference is pointing to it.

It frees the overhead of programmer to recollect the memory programatically.

Its the part of JVM

Thanks.
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It prevents you running out of memory, unless you do something daft.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Iliyan Ivanov wrote:Can you please explain to me in short what tha Garbage Collector does and why is it useful ?
Thank you



Helps you clear the unwanted/unnecessary memory occupied. In short doesn't let you run out of memory.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Each object that you create in your Java program takes up some memory. The Java virtual machine keeps track of what part of the computer's memory is occupied by objects and what part is free (ready to store new objects in).

In a programming language such as C++, you are required not only to allocate, but also to free the memory that you have allocated. When you are programming in C++, it can easily happen that you forget to free the memory of some object that you had allocated previously. Especially if the program becomes larger and more complicated, you can easily overlook that you should have freed some memory somewhere. When there are errors like that in a program, the program has memory leak: some block of memory is allocated and never freed.

Memory leaks can become a big problem, especially in long-running applications, where the amount of memory that the program has allocated grows and grows over time, slowing the whole system down, until eventually the program crashes because the computer doesn't have any more memory left to allocate.

In Java, this has been made much easier than in C++. You can create new objects, but you never have to free them yourself - the JVM frees objects automatically when they are not used anymore. The garbage collector is the process in the JVM that periodically frees the memory allocated for objects that are not used anymore.

Java's automatic memory management is a big advantage over C++, because you almost never have to worry about freeing objects, which means you can write your program in less time (you can be more productive) and the whole problem of memory leaks isn't there.
 
What does a metric clock look like? I bet it is nothing like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic