Forum Cross Platform with Xamarin

Xamarin Allocation problem reading from stream

Hello,

in my Crossover App, i save Images into sqlite-database.
I declared a column Byte[] for saving the Bytes from the Images into the database.
I create a PDF with pdfsharp.
When i load over 13 Pictures, i get following error:

#

{Java.Lang.OutOfMemoryError: Failed to allocate a 31961100 byte allocation with 16777216 free bytes and 29MB until OOM
at DWA.createPDF.createPDFnew (System.Boolean vermieter, System.Boolean unterschriftAnzeigen, System.Collections.Generic.List1[T] listTextbausteine, System.String betrag, System.Collections.Generic.List1[T] listSign, System.Int32 ve, System.Int32 we, System.String laufnr, System.String laufnrNM) [0x0858e] in C:\csvn\DWA-Crossover_V2\DWA\DWA\DWA\createPDF.cs:2273
at DWA.dokumente_vorschau.loadVorschau () [0x004fd] in C:\csvn\DWA-Crossover_V2\DWA\DWA\DWA\dokumente_vorschau.xaml.cs:191
at DWA.dokumente_vorschau..ctor (System.Collections.Generic.List1[T] listTextbausteine, System.Boolean unterschriftAnzeigen, System.Collections.Generic.List1[T] listSign) [0x0035b] in C:\csvn\DWA-Crossover_V2\DWA\DWA\DWA\dokumente_vorschau.xaml.cs:68
at DWA.dokumente_textbausteine.OnNextStepTapped (System.Object sender, System.EventArgs args) [0x00019] in C:\csvn\DWA-Crossover_V2\DWA\DWA\DWA\dokumente_textbausteine.xaml.cs:128
at Xamarin.Forms.TapGestureRecognizer.SendTapped (Xamarin.Forms.View sender) [0x0002e] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\TapGestureRecognizer.cs:46
at Xamarin.Forms.Platform.Android.TapGestureHandler.OnTap (System.Int32 count) [0x00028] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\TapGestureHandler.cs:36
at Xamarin.Forms.Platform.Android.InnerGestureListener.Android.Views.GestureDetector.IOnGestureListener.OnSingleTapUp (Android.Views.MotionEvent e) [0x0001c] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\InnerGestureListener.cs:125
at Android.Views.GestureDetector+IOnGestureListenerInvoker.n_OnSingleTapUp_Landroid_view_MotionEvent_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_e) [0x0000f] in <61dabd3f0b0446bc8b570d6071d995d7>:0
at (wrapper dynamic-method) System.Object:616a2488-951c-4c99-99be-a99f1369e014 (intptr,intptr,intptr)
--- End of managed Java.Lang.OutOfMemoryError stack trace ---
java.lang.OutOfMemoryError: Failed to allocate a 31961100 byte allocation with 16777216 free bytes and 29MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:726)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:702)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:740)
at md5b60ffeb829f638581ab2bb9b1a7f4f3f.InnerGestureListener.n_onSingleTapUp(Native Method)
at md5b60ffeb829f638581ab2bb9b1a7f4f3f.InnerGestureListener.onSingleTapUp(InnerGestureListener.java:79)
}

#

Here is my Code:

byte[] lb = null;
                    //MemoryStream lstr;
                    XImage imagefoto;
                    List<db.dwafotos> listeFoto = new List<db.dwafotos>();
                    for (int iFotos = 0; iFotos < listFotos.Count; iFotos++)
                    {
                        if (!listFotos[iFotos].del)
                        {
                            listeFoto = sync.syncWebdienst._cnSQLite.Query<db.dwafotos>("SELECT datei FROM dwafotos WHERE iddwafotosSQLite = " + listFotos[iFotos].iddwafotosSQLite).ToList();
                            if (listeFoto[0].datei.Length > 0)
                            {
                                //byte[] lb = DependencyService.Get<IPicture>().scaleBitmap(listeFoto[0].datei);
                                lb = listeFoto[0].datei;

                                using (imagefoto = XImage.FromStream(new MemoryStream(lb))) // Here is the error
                                {
                                    ..... 

                                    lb = null;
                                    //lstr.Dispose();
                                    imagefoto.Dispose();
                                    listeFoto.Clear();
                                }
                            }
                        }
                    }

Can you please help me.

Sign In or Register to comment.