-
Notifications
You must be signed in to change notification settings - Fork 564
Open
Labels
Area: BindingsIssues in Java Library Binding projects.Issues in Java Library Binding projects.
Milestone
Description
Steps to Reproduce
- Run a Xamarin.Android within Profiler and look at the allocations.
- Notice that many
JniMethodInfoinstances 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.
Metadata
Metadata
Assignees
Labels
Area: BindingsIssues in Java Library Binding projects.Issues in Java Library Binding projects.