Reputation: 970
I have some memory leak in my java application. I've made 2 heap dumps using jmap. And I see that there is 200 of objects which grow up and I suppouse that it's the reason of memory leak. But I need to verify that it's exactly the same objects. I use both MAT and visualvm for dump analyzing. So, is there any way to verify that 2 objects from different heap dumps are the same object? I mean may be there is some way to get a hashcode of this objects. I've tried to search by object id, but as I understood later it is an adress of object in memory, so it is useless for me.
Upvotes: 1
Views: 484
Reputation: 638
I know this question is old but I ended up here trying to find the answer via Google. I find the OQL easier to use in VisualVM than in MAT so I end up with the Object I'm looking for in VisualVM and want to see what references it in MAT. So I need to be able to get the object hashcode in VisualVM. When you have the hashcode in MAT you can get directly to the Object you want to see.
Once you find the Object you want in the Instances view, right click it and do Copy ID. This will get you the hashcode. You can then take this to MAT and find everything that references it, everything it references, etc.
So, to answer your question, you can compare the hashcode such that if two Object's have the same hashcode they are the same Object. The hashcode is the location in memory where the object was created. It can be moved around by the Garbage Collector, if it is long lived, etc. But for your purposes if two Objects are at the same location now then they are the same Object and have the same hashcode.
Upvotes: 1