• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Assignment question...

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



this code sample is on page 259 of n B.
****************************
Question is how many objects are eligible for GC after line "c1=null"
Answer is given 2(one is Short story and another is c1)

But according to me there should be 4
two are as the answer is given.
third is "c3" as it is set to null after invoking go() method.
forth is "c2"(not sure) as we are passing it as argument in go()
so in body of method it is being set to null (if i am right?)


**************************************************
What's your opinion???

Thanks
Deepak


[BSouther: Added UBB CODE tags]
[ March 04, 2008: Message edited by: Ben Souther ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Deepak Bahubal:

this code sample is on page 259 of n B.



When you quote your sources, please don't assume that everyone will know what 'n B' means.
 
Deepak Bobal
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry
I missed The letter K.Its K and B.
Kathy Sierra And Bert Bates.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Deepak,
There will be only 2 objects eligible for gc() as mentioned in answer.
c2 will not be set to null. because cb(object created in go) is a reference for c2. assigning cb=null dosnt means c2 is assigned to null.
So only c1 and 'Short' object inside it will ne eligible for gc().
Hope it has clear your dounts.
 
Deepak Bobal
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But what about c3 that is being set yo null by returning value of go().
 
Rahul Singhai
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Deepak,
c3 is never instantiated. it is just a reference variabble, so there is no aboject it is referring to rather it is referring to null value. So there is no point of garbage collection.
Hope it has cleared your query.
 
Deepak Bobal
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yah, Thanks Rahul You simply clears my doubts.
 
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can some tell me why c2 is not null.
Isnt cb pointing to c2 on the heap.So if cb is null wouldnt that mean, c2 is null as well.
Can some one make this more clear.
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nabila Mohammad:
Can some tell me why c2 is not null.
Isnt cb pointing to c2 on the heap.So if cb is null wouldnt that mean, c2 is null as well.
Can some one make this more clear.



The actual object, c2 is not null because the method go only holds a reference to c2 and not the actual object. That reference is null, not the object.
 
Nabila Mohammad
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got it.
Thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic