Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xamarian.Forms Out of memory exception #83

Leonscape opened this issue Jul 10, 2017 · 11 comments

Xamarian.Forms Out of memory exception #83

Leonscape opened this issue Jul 10, 2017 · 11 comments


Copy link

@Leonscape Leonscape commented Jul 10, 2017

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.

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 ---

Copy link

@jBijsterboschNL jBijsterboschNL commented Oct 20, 2017

We are experiencing a memory leak as well in the Android SignaturePad. We're running Xamarin.Forms version 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!

Copy link

@devjinho devjinho commented Oct 23, 2017

I`m having a same issue.

  • Xamarin.Forms
  • SignaturePad.Forms version 2.1.0

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)

Copy link

@jBijsterboschNL jBijsterboschNL commented Dec 5, 2017

@mattleibow any updates on this issue?

Copy link

@markolazic88 markolazic88 commented Dec 9, 2017

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.

Copy link

@jBijsterboschNL jBijsterboschNL commented Dec 12, 2017

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.

Copy link

@markolazic88 markolazic88 commented Dec 12, 2017

Hey @jBijsterboschNL, thanks for pointing this out.
Are you trying the example from my GitHub repo? I made a small mistake at line 27 of SignaturePage.xaml.cs, because I checked in GC.Collect(0) call instead of GC.Collect(). I was testing GC.Collect(0), which should perform only Minor collection on the Mono heap, but it does not do the trick for SignaturePad. You can see in the blog post that I was referring to GC.Collect() call. Also make sure that the line is uncommented. It is commented out by default to demonstrate that the issue exists.

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.

Copy link

@jBijsterboschNL jBijsterboschNL commented Dec 12, 2017

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!

@mattleibow mattleibow added this to To do in Triage May 15, 2018
Copy link

@mattleibow mattleibow commented May 18, 2018

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:

I hope to release a preview soon so that this can tested in the real world due to some major improvements.

Copy link

@VladislavAntonyuk VladislavAntonyuk commented Mar 9, 2019

@mattleibow it is still reproduced

Copy link

@ehansenp ehansenp commented May 25, 2020

I found that error. When i check all code, there is error type value properti.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
To do
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants