Android Question OutOfMemory Crash: What does this code do?

Discussion in 'Android Questions' started by Turbo3, Jun 22, 2015.

  1. Turbo3

    Turbo3 Active Member Licensed User

    Code:
    Dim r As Reflector
            r.RunStaticMethod(
    "java.lang.System""gc"NullNull)
    After releasing a new version of my app I have been getting crash reports of "OutOfMemory" like this invoked after calling canvas.initialize. Why are three bitmaps being created?
    Code:
    java.lang.OutOfMemoryError
    at android.graphics.Bitmap.nativeCreate(Native Method)
    at android.graphics.Bitmap.createBitmap(
    Bitmap.java:928)
    at android.graphics.Bitmap.createBitmap(
    Bitmap.java:901)
    at android.graphics.Bitmap.createBitmap(
    Bitmap.java:868)
    at anywheresoftware.b4a.objects.drawable.CanvasWrapper.Initialize(CanvasWrapper.java:
    76)
    One solution recommended adding the above code to Activity_Pause (UserClosed=true)

    Out of 10 crashes 8 are from Galaxy devices which seem to have a problem with memory allocation. The other two are from a Sharp and Fujitsu phone.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    It creates a single bitmap. The stack trace can be a bit confusing.

    What are you using the canvas for? Can you post the relevant code?
     
  3. Turbo3

    Turbo3 Active Member Licensed User

    Canvas is used by DrawColor(called once), DrawLine(called 7 times), DrawRect(called 10 times), and DrawText (called 16 times).

    I thought the RunStaticMethod might be calling garbage collection because of the"gc". Not sure I see how it creates a bitmap. The "What does this code do?" was not referring to the stack trace but the code someone listed to prevent the outofmemory error.

    I know the createBitmap in the stack trace creates a bitmap I just don't understand why it is creating three of them. You only need one for the canvas, right?
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    1. The gc call is not required.
    2. It creates a single bitmap not three.
     
  5. Turbo3

    Turbo3 Active Member Licensed User

    Yes of course, only one bitmap. I will remove the gc call. Thanks.
     
  6. Turbo3

    Turbo3 Active Member Licensed User

    Actually I never did get an answer to what this code does? Does anybody know?
    Code:
    Dim r As Reflector
            r.RunStaticMethod(
    "java.lang.System""gc"NullNull)
     
  7. DonManfred

    DonManfred Expert Licensed User

    hibrid0 and Peter Simpson like this.
  8. Turbo3

    Turbo3 Active Member Licensed User

    Thanks, let me know what you find.
     
  9. Turbo3

    Turbo3 Active Member Licensed User

    Found it.
     
Loading...