wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes dout regarding garbage collection 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 "dout regarding garbage collection" Watch "dout regarding garbage collection" New topic
Author

dout regarding garbage collection

nagaraj raja
Ranch Hand

Joined: Aug 06, 2005
Posts: 36
hai ,

Here i am thinking answer is c is it right plz explain?

Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

How about A?

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

But you know what, I think combining String Objects and a question about Garbage Collection together is just mean. It ends up asking about two seperate things.

1. Garbage Collection
2. Which Strings are in the String Pool and which are Objects on the heap.

Mark
Rubens Gomes
Greenhorn

Joined: Apr 26, 2005
Posts: 22
b) 1 --> "Nick" is the only object which does not have a stack variable reference pointing to it. The other Strings have references to them.


Rubens Gomes<br />SCJP 1.4 (96%)<br /><a href="http://www.rubens-gomes.com" target="_blank" rel="nofollow">www.rubens-gomes.com</a>
Shivani Chandna
Ranch Hand

Joined: Sep 18, 2004
Posts: 380

String name;
String newName = "Nick";
newName = "Jason";
name = "Frieda";
String newestName = name;
name = null;
//Line A


I think it should be 2 ....
name and "Nick" string object lost

am i wrong?


/** Code speaks louder than words */
Arvind Giri
Ranch Hand

Joined: Jun 26, 2005
Posts: 91
I think

< (b) 1 > is correct.

As there were only 3 objects and 2 are being referenced.
So its "NICK" which is eligible for garbage collection.
further u can't take name as object its only reference variable.


Regards<br /> <br />Arvind Giri<br />MCA,SCJP 1.4,SCWCD 1.4<br />Looking for SCDJWS
Shivani Chandna
Ranch Hand

Joined: Sep 18, 2004
Posts: 380
Originally posted by Arvind Giri:
[QBfurther u can't take name as object its only reference variable.[/QB]


Right if newestName didnt refer to the object refer by name then doing name=null wd make 2 objects elegible for GC. Thanks !
Steve Sugden
Greenhorn

Joined: Aug 20, 2005
Posts: 8
For what its worth, I agree with Rubens and Arvind. "Nick" appears to be the only String object not referenced.

Are we right? Can I have my certificate now?

 
Consider Paul's rocket mass heater.
 
subject: dout regarding garbage collection
 
Similar Threads
Garbage collection & string literal pool
garbage collection question
Garbage collection
Garbage Collection????
doubt on garbage collection