T Turbo3 Active Member Licensed User Longtime User Jun 22, 2015 #1 Code: Copy Dim r As Reflector r.RunStaticMethod("java.lang.System", "gc", Null, Null) 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: Copy 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.
Code: Copy Dim r As Reflector r.RunStaticMethod("java.lang.System", "gc", Null, Null) 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: Copy 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.
Erel B4X founder Staff member Licensed User Longtime User Jun 23, 2015 #2 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? Upvote 0
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?
T Turbo3 Active Member Licensed User Longtime User Jun 23, 2015 #3 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? Upvote 0
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?
Erel B4X founder Staff member Licensed User Longtime User Jun 23, 2015 #4 1. The gc call is not required. 2. It creates a single bitmap not three. Upvote 0
T Turbo3 Active Member Licensed User Longtime User Jun 23, 2015 #5 Yes of course, only one bitmap. I will remove the gc call. Thanks. Upvote 0
T Turbo3 Active Member Licensed User Longtime User Jun 25, 2015 #6 Actually I never did get an answer to what this code does? Does anybody know? Code: Copy Dim r As Reflector r.RunStaticMethod("java.lang.System", "gc", Null, Null) Upvote 0
Actually I never did get an answer to what this code does? Does anybody know? Code: Copy Dim r As Reflector r.RunStaticMethod("java.lang.System", "gc", Null, Null)
DonManfred Expert Licensed User Longtime User Jun 25, 2015 #7 Turbo3 said: Actually I never did get an answer to what this code does? Click to expand... Let me google that for you Upvote 0
Turbo3 said: Actually I never did get an answer to what this code does? Click to expand... Let me google that for you
T Turbo3 Active Member Licensed User Longtime User Jun 25, 2015 #8 Thanks, let me know what you find. Upvote 0
T Turbo3 Active Member Licensed User Longtime User Jun 25, 2015 #9 Found it. The java.lang.System.gc() method runs the garbage collector. Calling this suggests that the Java Virtual Machine expend effort toward recycling unused objects in order to make the memory they currently occupy available for quick reuse. Click to expand... Upvote 0
Found it. The java.lang.System.gc() method runs the garbage collector. Calling this suggests that the Java Virtual Machine expend effort toward recycling unused objects in order to make the memory they currently occupy available for quick reuse. Click to expand...