March 17, 2010 at 10:12 pm
· Filed under Java
Given an inner class object, how do you use reflection to obtain a reference to the outer class? this$0.
Field parent = inner.getClass().getDeclaredField("this$0");
parent.setAccessible(true);
Object outer = parent.get(inner);
If it is a nested inner class, increment the 0.
Permalink
March 17, 2010 at 8:28 pm
· Filed under Tech
I used QTP to simulate a repeating user scenario in order to trace a memory leak with YourKit over time. So I’m using this quick & dirty function to poll the application regularly about it’s raw memory usage.
Function GetMemory
pid = GetWindow().GetROProperty("process id")
Set wmiService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set resultset = wmiService.ExecQuery("SELECT WorkingSetSize FROM Win32_Process WHERE Handle=" & pid)
For Each result In resultset
GetMemory = Int(result.WorkingSetSize)
Next
End Function
GetWindow() returns a reference to the application window.
It seems even though I SELECT only WorkingSetSize I could get other information such as Handle from the result.
The For Each loop was an easy way out since I didn’t know how to access the first element.
Reference: http://www.learnqtp.com/windows-management-instrumentation-wmi-qtp/
Permalink