File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Garbage Collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Garbage Collection" Watch "Garbage Collection" New topic
Author

Garbage Collection

joe ton
Greenhorn

Joined: Jul 31, 2006
Posts: 3
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

Joined: Dec 27, 2005
Posts: 1249

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.


The Best way to predict your future is to create it - Every great individual common man
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
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.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Simon Baker
Ranch Hand

Joined: Sep 09, 2004
Posts: 57
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Garbage Collection