File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Finding number of String objects in the heap.

 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using java core api (1.5) how can I find the number of instances of a class in the heap.

Say for example ; I want to find the number of instances of String object created in the heap , or present in the heap at this point of time.

Does the java management api provides anything of this sort ? If not in the core api then is there is any third party for this requirement.

Thanks in advance.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some profilers let you know about this. I cant remember the name... perhaps it was jProfiler ? Or was it the one that comes with the net beans IDE. I am just taking wild hunches here.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think there's any way to do with Java's core APIs - unless you consider the Java Platform Debugger Architecture to be part of the "core". The JVMTI has IterateOverInstancesOfClass, but you need to write C code to access it. the JDI is more Java-friendly, but I don't see a way to request events for creation and destruction of objects. Maybe I'm missing something.

Anyway, using existing profilers and IDEs is by far the easiest way to do this. JVMTI gives you a way to custom-make your own tool which can do just what you want. But if you want a solution that just uses the standard Java libraries, I don't think there is one.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jim Yingst:
but I don't see a way to request events for creation and destruction of objects. Maybe I'm missing something.


Thanks Jim and John.

I do not need events for creation and destruction of objects.I just want the number of instances of any given class in the heap at that point of time.

I will evaluate the stuffs mentioned by you.I am sure that those will be of use for my issue.

Thanks once again.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic