spotter
spotter

Reputation: 1216

Can one programatically determine how much memory is being retained due to java reference?

I'm not asking how much memory a single reference takes up. I'm wondering about in the inverse sense of garbage collection.

i.e. given reference X, how much memory is that reference not allowing the garbage collector to free.

can one do this?

Obviously if one can, and if one has a set of references (A B and C) then it's likely that there will be some overlap in memory being retained (i.e. A and B might both have some connection to the same bit of memory), that's ok.

the point would be, to try and figure out why a memory leak is happening. If one has a program with long lived objects, one can programatically figure out which of these objects is growing and then rinse and repeat on said objects.

so is it possible?

Upvotes: 3

Views: 189

Answers (1)

ddyer
ddyer

Reputation: 1786

MemoryMeasurer looks interesting, but I think the question is asking about the memory you don't know about - ie; memory is unexpectedly bloated and you're looking for clues why.

VisualVM has a memory profiler that will tell you what kind of object is being retained, which is a good place to start. I don't know of any tools that reverse this and tell you what objects are retaining them.

Upvotes: 1

Related Questions