Forums Register Login

GC Doubt

+Pie Number of slices to send: Send
Please have a look at the following code:



Answer: a,b,c

Well, Should not it be b(Sceptical about b),c.

Please clarify my doubt.

Thanks
+Pie Number of slices to send: Send
I am also doubting a.Also b seems to be not in answer.

a is false as you can make a request to GCor not can make a explicit call to the Garbage Collector.
b is false as if suppose before a object is in the way for GCed an could not be collected due to some live reference then second time the finalize will not be called at all.
[ January 18, 2007: Message edited by: Sanjeev Singh ]
+Pie Number of slices to send: Send
Well I think it probably depends how you read the question.

The finalise is always called before an object is garbage collected - I'd say that is true. It's just not always immediately before (i.e called the first time it was eligible), but it is always before. I'd doubt in the exam they'd give you a question that ambigious.

And again for invoking the gc using a runtime object, yes you can invoke it, but it doesn't say that it will do anything.
+Pie Number of slices to send: Send
ONLY B IS RIGHT
---WHENEVER A OBJECT IS ABOUT TO BE GARBAGE COLLECTED,BEFORETHIS OPERATION FINALIZER IS ALWAYS RUN.'
--YOU CAN ONLY REQUEST gARBAGE COLECTOR,YOU CANT BE SURE IT WILL RUN OR NOT
+Pie Number of slices to send: Send
Comments
1. a. is correct because you can explicitly call gc from a Runtime object
( I wrote code to so). Doesn't mean it will run.
2. b. is incorrect because finalize can be called on an object only once
(see K&B pg 253)
3. c and d are incorrect

So answer is a.

Where did you get this question from.
+Pie Number of slices to send: Send
See K&B ques 10 pg 263.

By "explicitly calling" the gc I understand as in the code below.
Am I mistaken ? The code compiles.

Runtime rt = Runtime.getRuntime();
rt.gc();
+Pie Number of slices to send: Send
This question is taken MindQ's Sun Certified Java Programmer Practice Test
Updated 4/7/99.

The answers that are given are a. b and c.

I disagree with b & c.

I would like one of our gurus to please answer this one.

Thanks
If you have a bad day in October, have a slice of banana cream pie. And 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 717 times.
Similar Threads
Threads question from MindQ
garbage collection's doubt
GC doubt!
GC doubt
GC question on MindQ no. 37
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 21:09:58.