-
Notifications
You must be signed in to change notification settings - Fork 150
Xamarian.Forms Out of memory exception #83
Comments
We are experiencing a memory leak as well in the Android SignaturePad. We're running Xamarin.Forms version 2.3.4.270 and Xamarin.Controls.SignaturePad.Forms version 2.2.0. We have a ContentPage with a SignaturePad.Forms.SignaturePadView control on it. When navigating to this page back and forth everything works as expected. When navigating to this page and draw something, then navigate back and again navigate to this page (with the SignaturePadView) and draw something (repeating this a couple of time), we also get the same exception as described above. We're not even calling the GetImageStreamAsync() method yet! Could you investigate this issue, as we are running this on a Production environment. Might be that some Canvas, Bitmaps or something related doesn't get disposed properly inside the SignaturePad? Calling the SignaturePadView Clear() method doesn't solve this issue either. Note: this ONLY happens on Android! |
I`m having a same issue.
After disposing the GetImagetStreamAsync() mehotd, calling the Clear() method bumps up a memory bit, but, still it occurs OutOfMemoryError. (In my case, 15+ times uses) |
@mattleibow any updates on this issue? |
Hey guys, I just wrote a detailed blog post on the subject. The workaround is to invoke explicit garbage collection after collecting the signature. I used @Leonscape's TestSignaturePad solution to demonstrate how GC.Collect() helps. |
Hi @markolazic88, thank you for your great detailed blog about this subject. Unfortunately the example that you've provided doesn't work how you've described it in your blog. The heap size isn't decreasing when a call to GC.Collect() has been made. In the Android Device Monitor I also got this strange error: "Invalid object in managed heap". This error also occurs when I hit the "Cause GC" button inside the Android Device Monitor tool and the heap size also won't shrink. |
Hey @jBijsterboschNL, thanks for pointing this out. Android Device Monitor works fine for me. Try other device (I am working on VS Android Emulator), or maybe something is not properly installed on your machine. Android "Cause GC" will not shrink heap size in this case, as Xamarin is still holding the reference to the bitmap image. When GC.Collect() is called, it will remove the reference and then it will call Android "Cause GC", which now is able to remove the big image. |
Hi @markolazic88, thanks for your quick reply. This morning I did try several attempts and I'd also noticed that there was a call to GC.Collect(0) and thought I'd also tested it with the default call GC.Collect(). Apparently not, because now it is working as you've described. Thanks for your assistance! |
I know this is an old issue, but is it still happening? I have been updating the project and trying to get all the fixes in for a brand new release. It may have been an issue with Xamarin.Forms or it may be SignaturePad. Times have changed, and things have improved. Hopefully. If you want to try out the latest bits from the CI system, you can get them here: https://jenkins.mono-project.com/job/Components-SignaturePad-Windows/lastSuccessfulBuild/Azure/ I hope to release a preview soon so that this can tested in the real world due to some major improvements. |
@mattleibow it is still reproduced |
I found that error. When i check all code, there is error type value properti. |
@ehansenp please create PR: https://github.com/VladislavAntonyuk/SignaturePad |
I'm having a problem with the signature pad on android under forms. After around 35 uses the app crashes with an OOM exception inside android. This was tested on a J3 phone with version 2.1.1 With version 1.5.1 this problem doesn't happen, and I can repeat the calling of the page as many times as I like. I've attached a demo solution that exhibits this problem.
TestSignaturePad.zip
07-10 16:40:23.766 I/MonoDroid( 6196): UNHANDLED EXCEPTION:
07-10 16:40:23.886 I/MonoDroid( 6196): Java.Lang.OutOfMemoryError: Failed to allocate a 2851212 byte allocation with 632184 free bytes and 617KB until OOM
07-10 16:40:23.886 I/MonoDroid( 6196): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <3fd174ff54b146228c505f23cf75ce71>:0
07-10 16:40:23.886 I/MonoDroid( 6196): at Java.Interop.JniEnvironment+StaticMethods.CallStaticObjectMethod (Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00069] in :0
07-10 16:40:23.886 I/MonoDroid( 6196): at Java.Interop.JniPeerMembers+JniStaticMethods.InvokeObjectMethod (System.String encodedMember, Java.Interop.JniArgumentValue* parameters) [0x00018] in :0
07-10 16:40:23.886 I/MonoDroid( 6196): at Android.Graphics.Bitmap.CreateBitmap (System.Int32 width, System.Int32 height, Android.Graphics.Bitmap+Config config) [0x0005a] in :0
07-10 16:40:23.886 I/MonoDroid( 6196): at Xamarin.Controls.InkPresenter.CreateBufferImage () [0x00047] in <1c8da6cdedc6484799a7f1284def41ac>:0
07-10 16:40:23.886 I/MonoDroid( 6196): at Xamarin.Controls.InkPresenter.OnDraw (Android.Graphics.Canvas canvas) [0x00044] in <1c8da6cdedc6484799a7f1284def41ac>:0
07-10 16:40:23.886 I/MonoDroid( 6196): at Android.Views.View.n_OnDraw_Landroid_graphics_Canvas_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_canvas) [0x0000f] in :0
07-10 16:40:23.886 I/MonoDroid( 6196): at (wrapper dynamic-method) System.Object:05e98750-69cc-4ddd-bc25-2dbaafb6a9ad (intptr,intptr,intptr)
07-10 16:40:23.886 I/MonoDroid( 6196): --- End of managed Java.Lang.OutOfMemoryError stack trace ---
The text was updated successfully, but these errors were encountered: