• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

How many are eligible for GC

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


How many objects are elgible for GC when control reaches //1
The answer says 10.
According to me it should be 11.
Can anyone explain?
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tina,



I stand in the same group as you Tina;
I think in the same way, as you:
What I think:


11 objects will be eligible for GC because tmp is local to
the for block and 11 objects are created inside the block,
and outside that block we don't have reference to the lastly
created Object, so 11 will be eligible for GC.



If we modify the code as:



Then we can say 10 objects are eligible for GC.


Tina, don't you think these GC questions are killing!
See my latest question on "GC"!


Regards,
cmbhatt
[ April 21, 2007: Message edited by: Chandra Bhatt ]
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ask your self :

how many object unreachable after running this code ?

12

11 Objects inside for loop + "BOOM"
 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello

The question explicitly says when control reaches to line 1, so we can't take "Boom" into account. i guess 11 is the correct answer.

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

12

11 Objects inside for loop + "BOOM"





I found it funny! Best possible answer to this!
Bu.
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Eisa,

Don't count Boom, it is on the String constant pool, GC has nothing to do with that. And "Boom" was not created using "new" operator.

Now ask yourself how many object eligible to GC.

Padma,
I do agree with you!
Cheers,



Regards,
cmbhatt
 
Arad Chear
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry guys

i confused i was in the same time saw an question about toString

and i thought its here , by the way

if BOOM not used after this code is it available for GC ?

in another words :

is the String pool will Grabaged if there is no access to it throw the program ?

Hassel iam still baby in java and my exam after 4 days

no body all time is true
 
I can't renounce my name. It's on all my stationery! And hinted in this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic