• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to tell how many objects are created

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This may seem like a very silly noobish question. But I was wondering how exactly can I tell how many objects are created in java?
And like when I am debugging in like eclipse or netbeans, is there anyway to keep track of the number of objects being created?

And like for here I am not exactly sure how many objects get created:


Does the code here create 6 objects in the end? or is it 5 since "d" is destroyed essentially?...
 
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Arrays are objects so when you create an array honding N objects you actually create N + 1 objects (the xtra one being the array itself).
If you know that X objects are created and the question asks how many objects are created you should answer X even if you know that Y of them have now become eligible for garbage collection.
This is because
1.) The question asked for how many were created not how many are left.
2.) You have no guarantee of when garbage collection actually happened.
 
j domanga
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does that mean you have 6 objects total created for the array? And another "Intege"r object "d" for a total of 7?

And also, is there anyway I can like check this using java tools or debugger in eclipse/netbeans?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic