How to get all objects present in memory?
public static void mai开发者_StackOverflow中文版n( String[] arg ){
MyClass object1 = new MyClass();
BigDecimal bd = new BigDecimal();
Object obj = new Object();
List allObjects = getAllObjects(); // return object1, bd, obj
;
;
;
}
Probably the easiest is getting a heap dump by VisualVM. JDK also includes related tools, as the jmap tool.
I fear there is no easy answer to do this during runtime, either you use Instrumentation How can I access Java heap objects without a reference? or write an agent http://java.sun.com/j2se/1.5.0/docs/guide/jvmti/jvmti.html
精彩评论