简体   繁体   中英

Xamarin Forms out of memory errors on orientation changes

I have a problem with Xamarin.Forms. When I rotate the orientation, or sometimes when I just try to open a new page I get an unexpected error.

See image here

0x21 in System.Diagnostics.Debugger.Mono_UnhandledException_internal

0x1 in System.Diagnostics.Debugger.Mono_UnhandledException

0x26 in object.7581e694-d3dd-45ce-9fdf-93ab5f3b26ee

0x11 in System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw

0x6A in Android.Runtime.JNIEnv.CallStaticObjectMethode at /User/builder/data/lance/monodroid-milon-monodroid-4.18-series/3b7ef0a7/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:1161,5

0x73 in Android.Graphics.Bitmap.CreateBitmap at /User/builder/data/lanes/monodroid-milon-monodroid- 4.18-series/3b7ef0a7/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Android.Graphics.Bitmap.cs:621,21

0x7 in Xamarin.Forms.Platform.Android.ButtonDrawable.CreateBitmap

0x41 in Xamarin.Forms.Platform.Android.ButtonDrawable.Draw

0x13 in Android.Graphics/Drawables/Drawable.n_Draw_Landroid_graphics_Canvas_at /User/builder/data/lanes/monodroid-milon-monodroid-4.18-series/3b7ef0a7/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Android.Graphics.Drawables/Drawable.cs:988,4

0x17 in object.7581e694-d3dd-45ce-9fdf-93ab5f3b26ee

This is the call stack with external code. When the android device logger is enabled it shows out of memory errors. I have no idea to solve this and any help would be appreciated!

Are you using a Backgroundimage or another Image inside your Pages?

I had the same issue. I resolved it by loading/unloading backgroundimage from pages on navigation:

public override OnAppearing(...) { this.backgroundimage.Source = null; }
public override OnDisappearing(..) { this.backgroundimage.Source = your ImageSource; }

Big backgroundimages caused crashes in my android app. the ios version seemed to be handling it throwing no exception.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM