Win a copy of Getting started with Java on the Raspberry Pi this week in the Raspberry Pi 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Liutauras Vilda
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Piet Souris

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.
 
When all four tires fall off your canoe, how many tiny ads does it take to build a doghouse?
Low Tech Laboratory
https://www.kickstarter.com/projects/paulwheaton/low-tech-0
reply
    Bookmark Topic Watch Topic
  • New Topic