Open
Description
Steps to Reproduce
- Run a Xamarin.Android within Profiler and look at the allocations.
- Notice that many
JniMethodInfo
instances are being allocated -- many thousands, depending on project setup. - Cry at all the allocations.
The cause of the allocations is that Android.Runtime.JNIEnv
is now largely a "legacy" API, superseded by Java.Interop. In order to avoid JNIEnv binding duplication, most of the JNIEnv
methods were updated to delegate to Java.Interop
:
public static unsafe IntPtr CallObjectMethod (IntPtr jobject, IntPtr jmethod)
{
return JniEnvironment.InstanceMethods.CallObjectMethod (new JniObjectReference (jobject), new JniMethodInfo (jmethod, isStatic: false)).Handle;
}
For any code using the legacy API, this can be expensive on the GC.
What we should do:
- Audit the xamarin-android codebase to ensure we're not using
JNIEnv.Call*Method()
within our own codebase. - Strongly suggest that all Java Library Binding projects set
$(AndroidCodegenTarget)
=XAJavaInterop1.