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 object creation and gargage collection Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "object creation and gargage collection" Watch "object creation and gargage collection" New topic
Author

object creation and gargage collection

Sandeep Shukla
Greenhorn

Joined: Oct 21, 2004
Posts: 5
when i create a object( say a hashmap object) , is that object lifecycle limited to the method call or is this object available for garbage collection.
another doubt which springs into my mind...what all objects are really eligible for garbage collection?
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
Object is eligible for garbage collection if there are no references to it. He is called unreachable.
Read this article
http://java.sun.com/developer/technicalArticles/ALT/RefObj/


SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
what all objects are really eligible for garbage collection?


First, When you try call System.gc() in your code, it's force Garbage Collection. (This solution have in all Application Server such as WebLogic).

Second, When some object not have referenced or object is null.


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
System.gc() does not force garbage collection.

I'd have thought there were many articles out there that make this fact clear so as to prevent misleading. i.e. I believe I am stating the obvious.


Tony Morris
Java Q&A (FAQ, Trivia)
Surasak Leenapongpanit
Ranch Hand

Joined: May 10, 2002
Posts: 341

System.gc() does not force garbage collection.


It depends on JVM to force garbage collection.
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
It NEVER forces garbage collection.
I'd have thought this myth would be dispelled by now?
Clearly, it is still floating around
[ October 22, 2004: Message edited by: Tony Morris ]
Daniel Salomons
Greenhorn

Joined: Oct 07, 2004
Posts: 5
The javadoc says this about System.gc():

gc

public static void gc()

Runs the garbage collector.

Calling the gc method suggests that the Java Virtual Machine expend effort toward recycling unused objects in order to make the memory they currently occupy available for quick reuse. When control returns from the method call, the Java Virtual Machine has made a best effort to reclaim space from all discarded objects.

To me, it seems that all objects are removed as far as possible by the JVM. If you are complaining that this is not so, maybe you have some references that are accessible for the JVM, but have become invisble to you. ;-)
Daniel
SCJP 1.4
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608

To me, it seems that all objects are removed as far as possible by the JVM.


You missed the word 'suggests'.
In practice, it very seldom works.
Also in practice, calling it is almost always a bad idea.

I can't believe I'm saying this again! I've seen this thread of communication hundreds of times!
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Here's a link to an article regarding garbage collection. Maybe it will help answer some of your questions.

One thing to keep in mind - when it comes to garbage collection, there are virtually no guarantees. You never know when or if garbage collection will take place. You can "suggest" that it take place, but you can't force it to.


SCJP Tipline, etc.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: object creation and gargage collection
 
Similar Threads
Tech Word Game
Object Reference
GC
doubt on garbage collection
Garbage Collection doubt