7

If we have 300 classes in an application, is it possible to monitor how many instances of each class we have at a given time? Is it possible to know how much memory each instance is consuming?

Thanks

6 Answers 6

3

JDK 1.6 includes a tool called jvisualvm, which allows you to view lots of information about your running Java program, including memory usage, threads, etc. You could also use a profiler to see this kind of information. The profiler in NetBeans looks a lot like JVisualVM.

Sign up to request clarification or add additional context in comments.

Comments

2

I personally like Yourkit. It has a very good UI and comes with a 30 day trial. The details are also pretty extensive.

The online help document in that site should help you on how to set things up for running it.

Comments

1

use profiler4j or pmd

personally i like profiler4J for its ease of use and simple graphics :)

Comments

0

use jvisualvm.exe it is part of the JDK6

2 Comments

Does JVisualVM show instance counts and memory size by class? I know it shows thread activity and overall memory footprint, etc., but I didn't think it had the features the OP was looking for.
visualvm.dev.java.net/features.html Take and browse heap dumps. When you need to browse contents of application memory or uncover a memory leak in your application, you'll find the built-in HeapWalker tool really handy. It can read files written in hprof format and is also able to browse heap dumps created by the JVM on an OutOfMemoryException.
0

Most profilers will give you this information. I'm personally familiar with JProfiler, but I expect any worthwhile profiler would let you do this.

For a more low-tech solution, you could even trigger a heap dump from your application and then look through it with an application like jhat. The interface leaves a lot to be desired, though, and profilers would be much more comfortable to use in any non-trivial case.

Edit: here is an example of the memory screen for JProfiler, and you can also investigate the reference chain.

Comments

0

You could use a Java profiler, depending on which web container (if it's a web-app) you're deploying to you can try alot of different profilers: http://java-source.net/open-source/profilers

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.