Forums Register Login

object creation and gargage collection

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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/
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 


System.gc() does not force garbage collection.



It depends on JVM to force garbage collection.
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
 


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!
+Pie Number of slices to send: Send
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.
You got style baby! More than this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 850 times.
Similar Threads
doubt on garbage collection
Garbage Collection doubt
GC
Object Reference
Tech Word Game
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:54:43.