My question is different from this I’ve done profiling of my application it is too slow.
After completion of one process I have seen some live objects in the heap walker.
Though we are caching some data from database to HashMap but the heap walker shows me some live objects like Resultset.getString and Statement.getString which should not be there.
HashMap.put() taking very less memory then above two methods.
Have I done everything fine and is this analysis right? OR I am missing anything and the memory is occupied by HashMap itself and HeapWalker is just showing me methods of JDBC (getString and executeQuery).
Since you’re talking about methods, I guess you’re looking at the “Allocations” view of the heap walker. That view shows where objects have been created, not where objects are referenced. There’s a screen cast that explains allocation recording in JProfiler.
HashMap.putwill not allocate a lot of memory, it just creates small “Entry” objects that are are used to store key-value pairs. The objects that take a lot of memory are created before you put them into the hash map.Resultset.getStringandStatement.getStringcreate the String objects that you read from your database. So it’s reasonable to assume that some of these objects are longer-lived.To find out why objects are still on the heap, you should go to the reference view, select incoming references and search for the “path to GC root”. The “biggest objects” view is also very helpful in tracking down excessive memory usage.