Android Question [Solved] "Failed to allocate memory" error

Branksey

Member
Licensed User
My app has been working perfectly for months, and I wanted to modify it slightly. I added two lines of code to a service module (comms) and I get a "failed to allocate memory" error message immediately after the app has loaded.
If I comment out those two lines of code, I don't get the error.
If I set a breakpoint on the two lines of code, the breakpoint is not hit.
The two lines of code are not in the "starter" service where the error is reportedly happening at line 107.
I don't expect anyone to solve the issue from these brief details, but perhaps someone can help me understand what the error log is saying, and suggest possible solutions.
Many thanks.

<CODE>
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (comms) Create ***
** Service (comms) Start **
java.lang.OutOfMemoryError: Failed to allocate a 184560016 byte allocation with 6291456 free bytes and 58MB until OOM, target footprint 78779456, growth limit 134217728
at anywheresoftware.b4a.shell.ShellConnector.readObject(ShellConnector.java:281)
at anywheresoftware.b4a.shell.ShellConnector.readList(ShellConnector.java:222)
at anywheresoftware.b4a.shell.Shell.getStateAfterUserSub(Shell.java:513)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:414)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:146)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at b4a.easyhost.comms._newdata(comms.java:139)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:318)
at anywheresoftware.b4a.debug.Debug.CallSubNew2(Debug.java:285)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.keywords.Common.CallSubDebug2(Common.java:1058)
at b4a.easyhost.starter._astream_newdata(starter.java:211)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:146)
at anywheresoftware.b4a.BA$2.run(BA.java:387)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7386)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)
Error occurred on line: 107 (Starter)
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.keywords.Common.CallSubDebug2(Common.java:1058)
at b4a.easyhost.starter._astream_newdata(starter.java:211)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:146)
at anywheresoftware.b4a.BA$2.run(BA.java:387)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7386)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:336)
at anywheresoftware.b4a.debug.Debug.CallSubNew2(Debug.java:285)
... 17 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:318)
... 18 more
Caused by: java.lang.RuntimeException: java.lang.OutOfMemoryError: Failed to allocate a 184560016 byte allocation with 6291456 free bytes and 58MB until OOM, target footprint 78779456, growth limit 134217728
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:177)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at b4a.easyhost.comms._newdata(comms.java:139)
... 20 more
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 184560016 byte allocation with 6291456 free bytes and 58MB until OOM, target footprint 78779456, growth limit 134217728
at anywheresoftware.b4a.shell.ShellConnector.readObject(ShellConnector.java:281)
at anywheresoftware.b4a.shell.ShellConnector.readList(ShellConnector.java:222)
at anywheresoftware.b4a.shell.Shell.getStateAfterUserSub(Shell.java:513)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:414)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:146)
... 22 more
java.lang.RuntimeException: java.io.EOFException
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:177)
at anywheresoftware.b4a.BA$2.run(BA.java:387)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7386)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)
Caused by: java.io.EOFException
at java.io.DataInputStream.readByte(DataInputStream.java:270)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:344)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:146)
... 8 more
</CODE>
 

DonManfred

Expert
Licensed User
Longtime User
: Failed to allocate a 184560016 byte allocation with 6291456 free bytes and 58MB until OOM
What is the reason to try to allocate 184560016 bytes? What are you doing here? That´s 184 MB...
 
Upvote 0

Branksey

Member
Licensed User
Thank you for your reply.
Yes, I know. I'm not doing anything that requires such a huge amount of memory. I'm simply receiving a text string of formatted data and displaying it in a table. It feels like a memory leak, but I can't see any possible reason for that. The fact that I can make it go away by commenting out two lines of code, and yet those lines of code are never executed is the most puzzling thing for me.
 
Upvote 0

Branksey

Member
Licensed User
I have managed to reproduce the OOM problem with a tiny project. I have put comments against the lines that will prevent the crash if they are removed. None of this makes any sense to me, so I'm hoping that it makes sense to someone.
Many thanks for any help.
 

Attachments

  • OOM_crash.zip
    4.2 KB · Views: 176
Upvote 0

Branksey

Member
Licensed User
I am running it on an Android 10 tablet via a USB cable, in debug mode, if that makes a difference. I am using B4A 12.20 (64 bit).

Here is the error log:
Logger connected to: B4695F3BDD8E109
--------- beginning of crash
--------- beginning of system
--------- beginning of main
Copying updated assets files (8)
*** Service (starter) Create ***
java.lang.OutOfMemoryError: Failed to allocate a 184560016 byte allocation with 2097152 free bytes and 60MB until OOM, target footprint 72990712, growth limit 134217728
at anywheresoftware.b4a.shell.ShellConnector.readObject(ShellConnector.java:281)
at anywheresoftware.b4a.shell.ShellConnector.readList(ShellConnector.java:222)
at anywheresoftware.b4a.shell.Shell.getStateAfterUserSub(Shell.java:513)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:414)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at b4a.easyhost.starter.onCreate(starter.java:56)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3981)
at android.app.ActivityThread.access$1600(ActivityThread.java:226)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1900)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7386)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)
java.lang.RuntimeException: Unable to create service b4a.easyhost.starter: java.lang.RuntimeException: java.lang.OutOfMemoryError: Failed to allocate a 184560016 byte allocation with 2097152 free bytes and 60MB until OOM, target footprint 72990712, growth limit 134217728
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3993)
at android.app.ActivityThread.access$1600(ActivityThread.java:226)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1900)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7386)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)
Caused by: java.lang.RuntimeException: java.lang.OutOfMemoryError: Failed to allocate a 184560016 byte allocation with 2097152 free bytes and 60MB until OOM, target footprint 72990712, growth limit 134217728
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:188)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at b4a.easyhost.starter.onCreate(starter.java:56)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3981)
... 8 more
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 184560016 byte allocation with 2097152 free bytes and 60MB until OOM, target footprint 72990712, growth limit 134217728
at anywheresoftware.b4a.shell.ShellConnector.readObject(ShellConnector.java:281)
at anywheresoftware.b4a.shell.ShellConnector.readList(ShellConnector.java:222)
at anywheresoftware.b4a.shell.Shell.getStateAfterUserSub(Shell.java:513)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:414)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
... 11 more
 
Last edited:
Upvote 0

Branksey

Member
Licensed User
UPDATE:
It also crashes on an Android 9 phone and on an Android 6 phone.
I installed B4A on another computer, and it also crashes when using that one, so it doesn't seem to be related to my computer or target device.
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
I tested this. Like @agraham I did not have any problems. I saw some missing subs, but adding them did not change things.
I added logs. ???
 

Attachments

  • EasyHost.zip
    9 KB · Views: 160
Upvote 0

Branksey

Member
Licensed User
Thank you for your reply. Running your project in Release mode via a USB cable I do not get the OOM error:

*** Service (starter) Create ***
Here 3
Here 4
** Service (starter) Start **
** Activity (main) Create (first time) **
Here 9
** Activity (main) Resume **
*** Service (comms) Create ***
** Service (comms) Start **


However, running it in Debug mode via a USB cable I still get the error. There is a 5 second delay after the "Here 4" before the OOM error occurs:

Copying updated assets files (8)
*** Service (starter) Create ***
Here 3
Here 4
java.lang.OutOfMemoryError: Failed to allocate a 184560016 byte allocation with 6291456 free bytes and 60MB until OOM, target footprint 77184248, growth limit 134217728
at anywheresoftware.b4a.shell.ShellConnector.readObject(ShellConnector.java:281)
at anywheresoftware.b4a.shell.ShellConnector.readList(ShellConnector.java:222)
at anywheresoftware.b4a.shell.Shell.getStateAfterUserSub(Shell.java:513)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:414)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at b4a.easyhost.starter.onCreate(starter.java:56)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3981)
at android.app.ActivityThread.access$1600(ActivityThread.java:226)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1900)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7386)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)
java.lang.RuntimeException: Unable to create service b4a.easyhost.starter: java.lang.RuntimeException: java.lang.OutOfMemoryError: Failed to allocate a 184560016 byte allocation with 6291456 free bytes and 60MB until OOM, target footprint 77184248, growth limit 134217728
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3993)
at android.app.ActivityThread.access$1600(ActivityThread.java:226)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1900)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7386)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)
Caused by: java.lang.RuntimeException: java.lang.OutOfMemoryError: Failed to allocate a 184560016 byte allocation with 6291456 free bytes and 60MB until OOM, target footprint 77184248, growth limit 134217728
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:188)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at b4a.easyhost.starter.onCreate(starter.java:56)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3981)
... 8 more
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 184560016 byte allocation with 6291456 free bytes and 60MB until OOM, target footprint 77184248, growth limit 134217728
at anywheresoftware.b4a.shell.ShellConnector.readObject(ShellConnector.java:281)
at anywheresoftware.b4a.shell.ShellConnector.readList(ShellConnector.java:222)
at anywheresoftware.b4a.shell.Shell.getStateAfterUserSub(Shell.java:513)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:414)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
... 11 more
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
@Branksey , yes that gives me the same error as you.

If it only happens in debug mode, it could be a timing problem.
Perhaps Comms does not yet fully exist after Here 4, which restarts Starter and we have an infinite loop.
 
Last edited:
Upvote 0

Branksey

Member
Licensed User
@WiL, that's certainly a possible explanation. If I set a break point and step through the code the error doesn't happen, which supports your theory. I'm just surprised that I've never encountered this type of error before. Many thanks for your time and help, it's greatly appreciated.
 
Upvote 0
Top