Android framework version
net10.0-android
Affected platform version
VS 18.4.11626.88 & 36.1.30/10.0.100
Description
The LayoutInflater.Inflate method can cause a memory leak if the XML layout contains a reference to a custom .net view. A regression has been observed in net10-android. The same code works correctly in net9-android.
Minimal repro in attachment. The example contains a reference counter. You can switch the project from net10-android to net9-android to see the change in behavior.
net10-android-memory-leak-on-inflate.zip
Steps to Reproduce
- Create new net10-android application
- Add custom view
internal sealed class CustomView : global::Android.Views.View
{
public CustomView(Context? context) : base(context) { }
public CustomView(nint javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) { }
public CustomView(Context? context, IAttributeSet? attrs) : base(context, attrs) { }
public CustomView(Context? context, IAttributeSet? attrs, int defStyleAttr) : base(context, attrs, defStyleAttr) { }
public CustomView(Context? context, IAttributeSet? attrs, int defStyleAttr, int defStyleRes) : base(context, attrs, defStyleAttr, defStyleRes) { }
}
- Add layout
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<AndroidApp2.CustomView
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</FrameLayout>
- Inflate it's somewhere
LayoutInflater.Inflate(Resource.Layout.test, null, false);
- Observe memory leak
android-memory-leak.zip
Did you find any workaround?
Nothing.
Relevant log output
Android framework version
net10.0-android
Affected platform version
VS 18.4.11626.88 & 36.1.30/10.0.100
Description
The LayoutInflater.Inflate method can cause a memory leak if the XML layout contains a reference to a custom .net view. A regression has been observed in net10-android. The same code works correctly in net9-android.
Minimal repro in attachment. The example contains a reference counter. You can switch the project from net10-android to net9-android to see the change in behavior.
net10-android-memory-leak-on-inflate.zip
Steps to Reproduce
android-memory-leak.zip
Did you find any workaround?
Nothing.
Relevant log output