• 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
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

How to Count Num. of Objects

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can i count number of objects created in my program.
I want to count all String ,Array or any object that is created during my program execution.
 
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using normal Java, you can't count the instances of arbitrary classes. You can count the instances of your own classes, if you code instance-counting into them.

The JVM has profiling and debugging interfaces that do allow you to count instances of classes. However, an ordinary application shouldn't, and possibly can't, use these interfaces.

Why do you want to count instances?
 
Vijay Arora
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
coz i m learning Java.


Thanks & Regards
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Netbeans has a profiler that looks promising. I haven't used it myself for memory profiling, but maybe you can try it out and let us know how it works.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Vijay Arora:
coz i m learning Java



In that case, I would suggest moving on to the next topic in your Java education.
 
Marshal
Posts: 76102
362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Peter Chase:


In that case, I would suggest moving on to the next topic in your Java education.

Brilliant. In fact, counting "how many" objects you have is probably inconsistent with the conventions of object-oriented programming that instances of the same class have existence independent of one another.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a tool included with the JDK since Java 5 called JConsole, which you can use to see what a running Java application is doing.
 
reply
    Bookmark Topic Watch Topic
  • New Topic