File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Garbage Collection question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Garbage Collection question" Watch "Garbage Collection question" New topic
Author

Garbage Collection question

Shiva Mohan
Ranch Hand

Joined: Jan 05, 2006
Posts: 477
At what point is the object CREATED AT LINE 05 available for garbage collection.



Select most appropriate answer
a) At line 5
b) At line 7
c) At line 8
d) At line 10
e) At line 9
f) At line 12

My doubt is the answer option d or e is correct. Kindly help.
When the control comes to execute line 09,the anObj object reference started to point to new object SAMPLE.So I am asking is the answer e is correct.
[ September 27, 2006: Message edited by: Shiva Mohan ]
Chris Goad
Greenhorn

Joined: Jul 26, 2006
Posts: 16
E looks good to me. At that point, your variable would be referring to a new object since Strings are immutable.

Chris
Pedro Lobato Sena
Greenhorn

Joined: Apr 25, 2006
Posts: 16
"E" appears to be the right answer for me too.


SCWCD<br />SCJP<br /> <br />Pedro Henrique Lobato Sena
Anvi Dixit
Ranch Hand

Joined: Aug 28, 2006
Posts: 45
since the strings are immutable thats why a new object is created by this line
anObj = anObj.UpperString();

but my question is control cannot go back ...
only when the obj is assigned null then only it is valid entry for the GC..

please can anyone explain me..

thnx
Anvi
Sireesha Mullapudi
Ranch Hand

Joined: Jun 26, 2006
Posts: 74
Hi,

if the object has no references from any live thread,then it is eligible for the garbage collection.

when
anObj = anObj.toUpperCase();
is executed a new string object will be created and the reference anObj is pointing to it.But the old string doesn't have any references assigned to it. so it is eligible for garbage collection.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Garbage Collection question
 
Similar Threads
Can anyone help
Garbage collection..
Garbage Collection
GC
Garbage collect from Sarga.com Exam