File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage Collection

 
joe ton
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me know the detailed about Garbage Collection.

Explain Runtime.gc() and System.gc()...

Can I retrieve the unused objects... after it's garbage collector....
 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by joe ton:
[Q]Let me know the detailed about Garbage Collection.

Explain Runtime.gc() and System.gc()...

Can I retrieve the unused objects... after it's garbage collector....[/Q]


Check out this one

Reference Objects and Garbage Collections


This may be usefull for you. and also check the threads in this forum and beginner forum and SCJP forum.
 
Peter Chase
Ranch Hand
Posts: 1970
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You very rarely need to call gc(). It is not guaranteed to do anything. The JVM will usually work out when to do gc anyway.

To track the garbage collection of objects, you can use WeakReference objects. You may dedicate a thread to retrieving references from the queue associated with the WeakReferences and processing them accordingly. You may find it useful to subclass WeakReference, to store some additional information associated with the post-GC operation; if you do, be careful not to accidentally hard-reference the original object, or you will prevent it ever being GCd.

Sometimes, you may find SoftReference, or maybe even PhantomReference, more appropriate than WeakReference. The article cited by an earlier poster is a good thing to read, to guide your choice.

Check out also WeakHashMap. I find that useful occasionally.
 
Simon Baker
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also be aware of generational garbage collection, and the fact that the JVM implementation detail in this area changes from release to release. This is probably due to the importance in terms of performance.

See http://java.sun.com/docs/hotspot/gc1.4.2/ for an example of Sun's documentation on the GC (this one for JDK1.4.2).

Of course, in most cases you can probably just ignore the details and use pretty formulaic rules to select optimum heaps sizes.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic