Winston Gutkowski wrote:
Sam Pablo wrote:To simplify what I have written, as quoted above, I hope you know tools like JMap, JConsole, JStack, etc, which takes heap dumps.
As far as I can understand, they collect the number of heap objects (which are being referenced or ready for garbage collection). I too want to do the same, say for example, count the total number of objects in the heap, through a Java Code (I do not know how JMap or JConsole does it, maybe by native calls or through Java API).
And in addition to Tony's link, you might also want to look at the java.lang.management package that was introduced in 1.6.
However, before you go too far down this road, you'd better be able to justify your decision; because it sounds to me an awful lot like re-inventing the wheel.
I suspect you'll also find you're in a 'bleeding-edge' area where you can't rely on a lot of help, and will probably have to learn a lot of stuff by trial and error.
If someone asked me to do this, my first question to them would be: Why?
And if that didn't stop them, I'd come up with suitably padded estimates of how long it will take, and how much it'll cost (usually the nail in the coffin of any speculative project). And if that didn't stop them, then I'd accept defeat and settle in for a nice 3 month R&D exercise.![]()
One question for you though: Do you really think you need to retrieve objects in order to get a count of them?
Winston
Tony Docherty wrote:The simple answer is I don't know for sure. I know there is an instrumentation api and I believe these products use that.
A quick google found this site http://www.javamex.com/tutorials/memory/instrumentation.shtml which may be useful to you.
Tony Docherty wrote:
I want to retrieve objects from Java Heap, and want to write a code for the same.
Can you explain what you mean by this and also explain what you are trying to achieve.