Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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

Doubt Garbage Collection

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have doubt in GC.

Please anyone help me how number of object are eligible for GC from following list.

1.



2.



3.



4.


 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you think the answers are and why ?
 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please use the code brackets. I have pain in my eyes.

Hoping for your understanding
Bob
 
Prabhu Manickam
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bob!

I used brackets and indent properly.
 
Prabhu Manickam
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Deepak!

for 1, 2 and 3 - 2 objects ( not sure )
for 4 - 2 or 3 objects ( because initialising x by new Integer(5) ).
What is your suggestion?
 
Bob Wheeler
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prabhu Manickam wrote:Hi Bob!

I used brackets and indent properly.


Use the bracket buttons, if you edit your posts or send a new post(see button list above).
Then it looks like this:
 
Prabhu Manickam
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bob!
are you ok? This is the first time i am posting code.
 
Prabhu Manickam
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bob!
are you ok? This is the first time i am posting code.
 
Bob Wheeler
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prabhu Manickam wrote:Hi Bob!
are you ok? This is the first time i am posting code.


I know that you are new here. So welcome.
But I said:


...
Hoping for your understanding
Bob


You see, no offence meant. Just an advice, nothing more.
If you can't take it, ignore it.

Bob
 
Prabhu Manickam
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bob!
Coming to question. What is your suggestion?
 
Bob Wheeler
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prabhu Manickam wrote:Hi Bob!
Coming to question. What is your suggestion?


One object is eligible for all cases I assume (Edit: plus the gc object). So two altogether. !!!:
  • (1) one array object
  • (2) also one array obejct
  • (3) one Integer object
  • (4) also one Integer created by new keyword


  • Edit: We have only non-static variables here. So if gc sr to null, we lost all references
    to the non-static variables. Also the members of the array are either 0 or null, but not instantiated.
    Edit2: I forgot the gc obejct itself, so i head for the number 2 !!!

    cheers
    Bob
     
    Deepak Bala
    Bartender
    Posts: 6663
    5
    MyEclipse IDE Firefox Browser Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Prabhu Manickam wrote:Hi Deepak!

    for 1, 2 and 3 - 2 objects ( not sure )
    for 4 - 2 or 3 objects ( because initialising x by new Integer(5) ).
    What is your suggestion?



    For Q4, the int y is not an object. It is a primitive. Should the answer not be 2 ?

     
    Prabhu Manickam
    Greenhorn
    Posts: 9
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi Deepak!

    for Q4,
    what about the variable z?
     
    Deepak Bala
    Bartender
    Posts: 6663
    5
    MyEclipse IDE Firefox Browser Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Prabhu Manickam wrote:Hi Deepak!

    for Q4,
    what about the variable z?



    I am not sure if the reference z will automatically be boxed and stored as an object, without anybody using it. If it is then the answer is 3.
     
    What does a metric clock look like? I bet it is nothing like 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