• 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
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Garbage Collection for out of scope objects references

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
dear Ranchers,
I came across this question in one of the mocks.
Given this code, how many objects are eligible for GC at line 1


Now, 11 String objects are created and tmp holds reference to the last one.
The correct answer given is 10 objects eligible for GC, saying that even though tmp variable is out of scope, the local variable still has reference to it.

What I am thinking is at line 1, variable tmp is not available so there is no live reference that can access the object. So my answer is 11.

Anyone who can throw light on this.

Note: I don't know if this question is already being asked, because to me the search seems not much usable - it returns only posts dating to year 2001 and before for whatever reason.

thanks,
Roopesh.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are correct Roopesh. The answer should be 11 objects.

See the attached code for reference.

[ September 14, 2005: Message edited by: Barry Gaunt ]
 
Roopesh Gulecha
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bala,
That code is good and it helped.
Are you scjp certified??
I am appearing for the 1.4 exam next week.

Roopesh.
 
I've got no option but to sell you all for scientific experiments. Or a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic