• 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

Garbage collector

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hai everyone. I am new to this forum. Can anyone tell me the usage of garbage collectors in java
 
Ranch Hand
Posts: 296
Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why don't you start with any good Java book or this not very famous resource first, so we can talk about more specific things?
 
Sheriff
Posts: 5555
326
IntelliJ IDE Python Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We could, and some gladly would, talk for days about the ins and outs of the garbage collector. But the short answer is memory management.

In java don't have to explicitly manage our memory usage in the same way as we do in other languages such as C. The gc's job is to go round and clean up (free memory) from objects that are not being used anymore, specifically objects that are no longer referenced in your code.

There are a number configuration options for the gc to help you optimise its behavior and that's where the discussion can take some time. For the most part you won't need to worry about it at all, just let it do it's thing.
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

just let it do it's thing


i agree completely. it is very good at doing it's job. btw, calling gc() does not ensure that it will run.
 
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Peterwil

Welcome to Java ranch !!

may be link can help you getting started with GC in Java

http://www.artima.com/insidejvm/ed2/gc.html

Happy learning !!

Thanks
Abhay Agarwal


 
surlac surlacovich
Ranch Hand
Posts: 296
Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Randall Twede wrote:it is very good at doing it's job. btw, calling gc() does not ensure that it will run.


I agree that its doing good job, but I think it would be better to also have retain/release/autorelease mechanism which will allow to count references by yourself and release(deallocate) object right away, because as everybody knows GC cleans up memory with delay.
 
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

surlac surlacovich wrote:

Randall Twede wrote:it is very good at doing it's job. btw, calling gc() does not ensure that it will run.


I agree that its doing good job, but I think it would be better to also have retain/release/autorelease mechanism which will allow to count references by yourself and release(deallocate) object right away, because as everybody knows GC cleans up memory with delay.



What make you think that doing it yourself will NOT result in a delay?
 
Tim Cooke
Sheriff
Posts: 5555
326
IntelliJ IDE Python Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

surlac surlacovich wrote:I agree that its doing good job, but......


And so it begins. Buckle up children, you're in for a bumpy ride.
 
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

surlac surlacovich wrote:

Randall Twede wrote:it is very good at doing it's job. btw, calling gc() does not ensure that it will run.


I agree that its doing good job, but I think it would be better to also have retain/release/autorelease mechanism which will allow to count references by yourself and release(deallocate) object right away, because as everybody knows GC cleans up memory with delay.


The garbage collector in current Oracle JVM versions is much more sophisticated than you think. Garbage collection is a huge topic for which a lot of research has been done. So, it's hard to draw any conclusions about how efficient it is without being an expert. (I'm certainly not an expert with regard to GC).

Since Java 6 update 23, the Oracle JVM also includes escape analysis - a technique that checks if short-lived objects can be allocated on the stack instead of on the heap, which makes cleaning them up very cheap (in fact, it's automatic, when the method returns and the call stack unwinds). That sounds more or less like what you're proposing.

Fortunately escape analysis is also automatic, it would be really cumbersome if we as programmers would have to spend time thinking about low-level optimizations all the time.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic