The next generation Mordern iSeries Developer
"Il y a peu de choses qui me soient impossibles..."
The next generation Mordern iSeries Developer
thejwal pavithran wrote:in this code, i was expecting the finalize method to be called and the message "garbage collected" to be printed when system.gc() was called...but its not happening..please tell me what im missin.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Although you can code for a more specific finalize method for an object, that's generally not a good idea. Since you can't tell when the garbage collector will call this method, you can't be assured that your finalize method will be executed before the program terminates. Therefore, you shouldn't rely on the finalize method to handle any timely tasks.
"Il y a peu de choses qui me soient impossibles..."
No, it doesn’t. Nor does a System.gc() call, which is a sort of suggestion. The only thing which invokes finalize() is the JVM.thejwal pavithran wrote:yeah assigning null invokes finalize as pointed out by by steve..
Yogesh Gnanapraksam wrote:I became a little curious and tested this out in the following ways..
Test 1:
Output : hi
I commented only the line 'obj1 = null " only and then tried again..
Test 4 :
output : hi
Now finalize is not invoked.
Yogesh Gnanapraksam wrote:
Test 3:
output :
hi
garbage collected
This is where I am surprised. Call to Sytem.gc() makes the JVM run finalize!!
Why is this surprising???
Yogesh Gnanapraksam wrote:
Why is this surprising???
Why is this not happening in Test 2 ?
Yogesh Gnanapraksam wrote:System.gc() just makes a suggestion to run the GC and it is upto the JVM to decide to run it or not..
Yogesh Gnanapraksam wrote:System.gc() just makes a suggestion to run the GC and it is upto the JVM to decide to run it or not. From the above code runs ,it seems that JVM runs the GC (provided the object is not reachable) when System.gc() is invoked. It does not exit without running the GC. In this case too JVM might have exited as well without running the GC but it complied with the request.
So.... for this example, the "suggestion" argument probably doesn't apply here.
Henry Wong wrote:the JVM exited before the garbage collector ran. It is not mandatory for the GC to run prior to exiting.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Campbell Ritchie wrote:
No, it doesn’t. Nor does a System.gc() call, which is a sort of suggestion. The only thing which invokes finalize() is the JVM.thejwal pavithran wrote:yeah assigning null invokes finalize as pointed out by by steve..
"Il y a peu de choses qui me soient impossibles..."
Yogesh Gnanapraksam wrote:I am trying to get a better understanding with help from experts.I will put them into practice/educate my co-workers with these findings.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
"Il y a peu de choses qui me soient impossibles..."
Stevens Miller wrote:Understanding the GC is a good thing to pursue for a new Java programmer...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Stevens Miller wrote:Understanding the GC is a good thing to pursue for a new Java programmer...
I disagree completely.
Paul Clapham wrote:
Winston Gutkowski wrote:
Stevens Miller wrote:Understanding the GC is a good thing to pursue for a new Java programmer...
I disagree completely.
I agree with your disagreement. These forums seem to contain a lot of people obsessing over things which really don't make any difference.
Henry Wong wrote:
Paul Clapham wrote:
Winston Gutkowski wrote:
Stevens Miller wrote:Understanding the GC is a good thing to pursue for a new Java programmer...
I disagree completely.
I agree with your disagreement. These forums seem to contain a lot of people obsessing over things which really don't make any difference.
Since this debate seems to be heavily one sided among the experienced ranchers, I'll throw in a jab for the counter argument -- it's the devil's advocate side of my personality. In my opinion, if you are interested in learning something, go ahead and do it. Yes, it may be low on the usefulness scale. There may be other technologies that are more important. But learning is supposed to be interesting and fun, so if you have an interest in learning something, then by all means, dive into it.
Henry
"Il y a peu de choses qui me soient impossibles..."
Stevens Miller wrote:Forgive me for running off at the mouth (or the keyboard), but this is a beginner's forum, and our OP asked a perfectly reasonable question. When I got started in Java, I asked a lot of similar questions. I have a pretty thick skin (I'm a politician; we have those 8-) ), but people telling me I should be putting my time into other things when I'm in the process of exploring a new tool always rubbed me the wrong way. If our OP has been taking the good answers here to heart, he now knows a lot of what a competent Java programmer ought to know about the GC.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Time is mother nature's way of keeping everything from happening at once. And this is a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|