Android Question OutOfMemory error

Discussion in 'Android Questions' started by hibrid0, Jun 25, 2015.

  1. hibrid0

    hibrid0 Active Member Licensed User

    Hi guys, I'm creating an app to create a PDF file, the pdf file is created with PDFwriter, and have many images inside.

    I use the garbage Collector for images with the reflector lib.
    Tested in 3 Devices, and in the Device I really need run it, not work!!!

    Finally I run a Test on my phone and work fine with 10 or more pages.

    In Tablet test 1: (The real device client want to use this App)

    Total Pages Generate: 10
    Total Images used: 28
    Tablet: Lenovo Ideatab A3000 (IdeaTabA3000-H)
    CPU: MTk 8389/8125 Quad Core de 1,2 GHz
    RAM: 1GB
    Android version: 4.2

    In Phone Test 2:

    Total Pages Generate: 14
    Total Images used: 52
    Phone: Amazon FirePhone
    CPU: Snapdragon 800 2.2GHz Quad-core
    RAM: 2GB
    Android version: FireOS 4.6.1 (Kitkat 4.4)
    Work Very Faster

    In Tablet Test 3

    Total Pages Generate: 14
    Total Images used: 52
    Tablet: Lenovo Yoga 8" B6000-F
    CPU: MediaTek MT8125 Quad Core de 1,2 GHz
    RAM: 1GB
    Android version: 4.4.2
    Work Fine

    I add the code from Infoxmatrix to see the max memory, FreeMemory and TotalMemory from here

    And Here this part on the crash:

    PDF Convert
    max Memory 134217728
    FreeMemory 7611936
    totalMemory 37351424
    Memoria Disponible :102029.53125

    PDF Writer
    max Memory 134217728
    FreeMemory 28835040
    totalMemory 114974720
    Memoria Disponible :46951.21875

    I have in the manifest:

    To Insert Images I use this:

    Sub insertar_imagen2 (nombre_imagen As String, izquierda As Double, arriba As Double)
    LoadBitmapSample("", nombre_imagen,310120)


        PDFWriter1.addImage(mm2Points(izquierda),mm2Points(arriba), img_Logo)

    Dim Obj1,obj2 As Reflector
          Obj1.Target = img_Logo                            
    End Sub
    To Create PDF Page I use someting like this:

    Sub Hoja1
        PDFWriter1.setFont(fonts.SUBTYPE, fonts.TIMES_ROMAN)
        PDFWriter1.setFont2(fonts.SUBTYPE, fonts.TIMES_ROMAN, fonts.WIN_ANSI_ENCODING)

    "Image1", left, horizontal_position)
    end sub
    How can I solve to create more pages in the PDF in devices with low RAM?
    How can I create a Page then excute garbage Collector for everything have inside this page?

    I see this code in the forum.
    Dim r As Reflector
    Installing file.
    PackageAdded: package:createpdf.forms
    ** Activity (main) Create, isFirst = true **
    ** Activity (main) Resume **
    ** Activity (main) Pause, UserClosed = false **
    ** Activity (generar_borrador) Create, isFirst = true **
    PDF Convert
    PDF Writer
    generar_borrador_crear_pdf (B4A line: 111)
    PDFContent = PDFWriter1.outputToScreen
    at java.lang.AbstractStringBuilder.enlargeBuffer(
    at java.lang.AbstractStringBuilder.append0(
    at java.lang.StringBuilder.append(
    at com.rootsoft.pdfwriter.PDFDocument.toPDFString(
    at com.rootsoft.pdfwriter.PDFWriter.asString(
    at com.rootsoft.pdfwriter.myPDFWriter.outputToScreen(
    at createpdf.forms.generar_borrador._crear_pdf(
    at createpdf.forms.generar_borrador._activity_create(
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(
    at anywheresoftware.b4a.BA.raiseEvent2(
    at createpdf.forms.generar_borrador.afterFirstLayout(
    at createpdf.forms.generar_borrador.access$100(
    at createpdf.forms.generar_borrador$
    at android.os.Handler.handleCallback(
    at android.os.Handler.dispatchMessage(
    at android.os.Looper.loop(
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(
    at dalvik.system.NativeStart.main(Native Method)
    Last edited: Jun 26, 2015
  2. Erel

    Erel Administrator Staff Member Licensed User