Question

I'm looking through some hprof's, trying to find a memory leak.

My code saves references to Java Components from a target application I'm building upon. Using Eclipse MAT I can see some of these Components are referenced by my code alone. I'd like to be certain that the target app is finished with them, i.e. that it intended for them to be garbage collected.

In C# there is a Control IsDisposed property which if true basically means the application is done with that Control.

Is there an equivalent in Java, that can be seen in Eclipse MAT or any other hprof analyzer, which will conclusively tell you if a Component is left to be garbage collected?

I'd prefer to use a property to identify a Component as leaked as it's easier query the heap using this criteria, than 'every Component whose Path To GC Root ends in only my code'

Thanks

Était-ce utile?

La solution

querying the heap is very, very expensive. It means examining every object in the heap to see what is being referenced.

What you can do in Java is hold a WeakReference and after a garbage collection this will disappear. If it is retained there is still a use somewhere.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top