JniEnvironment.References.CreatedReference(JniObjectReference) Method

Definition

Account for the creation of a JNI Reference.

public static void CreatedReference (Java.Interop.JniObjectReference value);
static member CreatedReference : Java.Interop.JniObjectReference -> unit

Parameters

value
JniObjectReference

A JniObjectReference value containing a JNI Reference that was created.

Exceptions

value is not a JNI Local Reference.

Remarks

The LocalReferenceCount property provides an advisory value of the number of JNI Local References which Java.Interop has created. The GlobalReferenceCount property provides an advisory value of the number of JNI Global References which Java.Interop has created. The WeakGlobalReferenceCount property contains an advisory value of the number of JNI Weak Global References which Java.Interop has created. These counts are incremented whenever a JNI reference is created, e.g. from NewLocalRef() or NewGlobalRef(), and this count is decremented whenever a JNI Local Reference is destroyed, e.g. from Java.Interop.JniObjectReference.Dispose.

This accounting assumes a worldview in which Java.Interop can intervene wherever a JNI Local Reference can be created. This is not the case, as there are some scenarios where JNI Local References can be created without Java.Interop knowing about it. One such notable example is when using Platform Invoke to invoke a native Java_ C function which returns a JNI Local Reference (IntPtr). When such untrackable JNI Local References are created, this may result in future assertions failing within Java.Interop.JniRuntime.JniObjectReferenceManager.DeleteLocalReference when the tracked JNI Local Reference count becomes negative.

Use the CreatedLocalReference to notify Java.Interop that a JNI Local Reference has been created externally, so that the JNI Local Reference accounting doesn't generate future assertions.

Applies to