Possible Duplicate:
How to monitor Java memory usage?
My Java Program loads hash map with large number of values from the database. Is there any way through which I may know that how much memory each of my hash map is using during the program is running.
I am aware that it may not be a constant value but any near approximation will also do. Or maybe how much memory each of the hash map consumes while it is loaded with data from Sql Server.
Thanks
-
1You could come to a rough esimate if you execute the program in an IDE and use its profiling features. I.e. you could use Eclipse + TPTP.home– home2011年07月24日 09:12:54 +00:00Commented Jul 24, 2011 at 9:12
-
Yes I am using eclipse IDE. TPTP - can you clarify this a little more? ThanksJavaBits– JavaBits2011年07月24日 09:25:30 +00:00Commented Jul 24, 2011 at 9:25
-
@Mitch - its definitely related but not a duplicate.:-)JavaBits– JavaBits2011年07月24日 09:28:31 +00:00Commented Jul 24, 2011 at 9:28
-
JavaBits: well that's why the 'possible' is there I guess.Mitch Wheat– Mitch Wheat2011年07月24日 09:29:11 +00:00Commented Jul 24, 2011 at 9:29
-
@JavaBits: ...and as far as I can see the answer in that question will work for you. Determine memory before and after you fill the hash map....Mitch Wheat– Mitch Wheat2011年07月24日 09:30:20 +00:00Commented Jul 24, 2011 at 9:30
2 Answers 2
If you want to estimate the size of specific data structures at runtime, Heinz Kabutz's newsletter describes how to do this using instrumentation: Instrumentation Memory Counter.
Comments
If you want an estimate use a profiler like VisualVM or YourKit.
You could estimate how large an entry key/value is and multiply it by the number of entries.