aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Can anyone help 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 "Can anyone help" Watch "Can anyone help" New topic
Author

Can anyone help

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
At what point is the object anObj available for garbage collection.
01: public class Base{
02:
03: private void test() {
04:
05: if(true) {
06: String anObj = "sample";
07: String locObj = anObj;
08: anObj.trim();
09: anObj = null;
10: locObj.trim();
11: }
12: }
13:
14: static public void main(String[] a) {
15: new Base().test();
16: }
17:
18: }
Select most appropriate answer
a) After line 7
b) After line 8
c) After line 9
d) After line 10
e) After line 11
please help:
thank
Yaco
Balasubramanyam Kallavi
Greenhorn

Joined: Sep 22, 2000
Posts: 17
Hi:
I think the answer for your question is 'b' (After line 8). Immediately after line# 8, the 'anObj' reference has been assigned 'null', making the 'anObj' eligible for garbage collection.
Cheers,
Balu


Balasubramanyam Kallavi<BR>(kallavib@hotmail.com)
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20730
    ∞

PROPER NAMES ARE NOW REQUIRED!
See http://www.javaranch.com/ubb/Forum10/HTML/000180.html for details.


permaculture Wood Burning Stoves 2.0 - 4-DVD set
Kumareswark
Greenhorn

Joined: Sep 19, 2000
Posts: 3
Isn't 'C' is the answer. Till line 9 object still alive only after that object looses its ref.
mohit joshi
Ranch Hand

Joined: Sep 23, 2000
Posts: 243
At what point is the object anObj available for garbage collection.
01: public class Base{
02:
03: private void test() {
04:
05: if(true) {
06: String anObj = "sample";
I think the question really means at what point is the object referenced by variable anObj can be GCed. at line 6, an object reference variable of Type String is assigned a new String object which contains "sample". till line 10 this object is still reachable by the locObj reference variable.so it is only after the locObj goes out of scope in line 11 that the original object can be GCed.
Correct me if I am wrong.


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can anyone help