when the instance is garbage collected, it may result in a call to collect the garbage, which may result in garbage being collected. Or maybe not, it's all a bit fluid with GC. If you're implying it may result in an infinite loop I strongly doubt it. As mentioned, System.gc() is just a request to clean the garbage, it does not enforce it.
Joined: Mar 26, 2007
I had a doubt about infinite loop.
But my question is : whether that object will be garbage collected or not?
Either you have called the GC (JVM might not even call the GC when you say System.gc()) , or the JVM has called the GC , that is the reason that you have reached the finalize method of the objects to be collected.
Now if you again call GC from the finalize method , the GC might not be even called , as this has been called from within the finalize method.
It definitely won't be garbage-collected while finalize() is still running, if that's what you're worried about.
Calling System.gc() is almost always misconceived. Having a finalize() method is usually misconceived too. So calling System.gc() in finalize() is at the extreme end of bad ideas. But you won't get a crash or a hang (this isn't C++!). You just won't get whatever effect you were trying to achieve.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P
What if I call this.someMethod() in the finalize method? Will the object get garbage collcted? If not then again finalize method will be called? I think its called only once in the lifetime of object. So next time the object would be garbace collected automatically?