public DisposableObjectCollection <JvmObjectReference> GetOwnedMonitorInfo(JvmThreadReference thread, JvmNativeEnvironment nativeEnvironment) { DisposableObjectCollection <JvmObjectReference> result = new DisposableObjectCollection <JvmObjectReference>(); int ownedMonitorCount; IntPtr ownedMonitors; ThrowOnFailure(_rawInterface.GetOwnedMonitorInfo(_env, (jthread)thread, out ownedMonitorCount, out ownedMonitors)); try { unsafe { jobject *rawMonitors = (jobject *)ownedMonitors; for (int i = 0; i < ownedMonitorCount; i++) { result.Add(new JvmObjectReference(this, nativeEnvironment, rawMonitors[i], true)); } } return(result); } finally { if (ownedMonitors != IntPtr.Zero) { Deallocate(ownedMonitors); } } }