wood burning stoves 2.0*
The moose likes Java in General and the fly likes Finding number of String objects in the heap. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Finding number of String objects in the heap." Watch "Finding number of String objects in the heap." New topic
Author

Finding number of String objects in the heap.

Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
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.


Rahul Bhattacharjee
LinkedIn - Blog
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

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.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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.


"I'm not back." - Bill Harding, Twister
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Finding number of String objects in the heap.
 
Similar Threads
String Objects
Number of String objects
"Number Of Objects in Heap"
API
Performance of Multiple instances of tomcat