• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

CertGear question doubt

 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends,
I've this doubt,can someone tell me how many objects are created by this code??According to me:
9 Obejects-->"Hello","World","Hi World","Do Test","a","b","c",Vector v","x"

If I am correct,can someone tell me why "StringBuffer Object x" is not available for garbage collection ar #11??
Thanks in advance.
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because it is being referred to by the variable c.
 
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by jas oberai:
Hi Friends,
I've this doubt,can someone tell me how many objects are created by this code??According to me:
9 Obejects-->"Hello","World","Hi World","Do Test","a","b","c",Vector v","x"

If I am correct,can someone tell me why "StringBuffer Object x" is not available for garbage collection ar #11??
Thanks in advance.




Jas,
aren't a,b,c and x variables ? You cannot count them among objects created.
 
Jas Oberai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess "c is not referring x",c is referring to "Do Test".Please correct me if i am wrong and tell me James how many objects are created??
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
c is referring to a StringBuffer containing "Do Test". And, I believe you're right. It looks like 9 objects are created. Unless, of course, you count the Class objects that must be created by the classloader in order for you to instantiate the objects.
reply
    Bookmark Topic Watch Topic
  • New Topic