java.lang.OutOfMemoryError: Failed to allocate to 24 byte allocation with 0 free bytes and 3GB until OOM

0

I have an Android application that constantly sends several data to my server, I need this data to be sent constantly throughout the day, however, sending the data takes about an hour and then the application closes and it shows me this error:

java.lang.OutOfMemoryError: Failed to allocate a 24 byte allocation with 0 free bytes and 3GB until OOM

I tried what they say in this post to add in the% android:hardwareAccelerated="false" and android:largeHeap="true" but the app is still closing me.

This is the part of the code where I process the strings that I receive by bluetooth and sent to my server to insert the data in my BD.

private Handler mMainHandler = new Handler()
{

@Override
public void handleMessage(Message msg) {
    switch (msg.what) {

        case CONST.MSG_LEER:
            String readMessage =  msg.obj.toString();
            int charInicioCadena = readMessage.indexOf("#");
            int charInicioTiempo = readMessage.indexOf("{");
            int charInicioValor = readMessage.indexOf("(");
            int charInicioValor2 = readMessage.indexOf(")");
            int charFinCadena = readMessage.indexOf("~");//#lab{10000(~


            if (charFinCadena > 0) {
                try {
                    nombreDispositivo = readMessage.substring(charInicioCadena + 1, charInicioTiempo);

                switch (nombreDispositivo) {

                    case "ecg":
                        cuenta++;
                        segundo = readMessage.substring(charInicioTiempo + 1, charInicioValor);
                        valorECG = readMessage.substring(charInicioValor + 1, charFinCadena);//Valor ECG de tipo cadena
                        ecgValuefloat = Float.parseFloat(valorECG);
                        //checar minimo y maximo cada entrada

                        if(ecgValuefloat<Globals.valorMinimo){Globals.valorMinimo=ecgValuefloat;}
                        if(ecgValuefloat>Globals.valorMaximo) {Globals.valorMaximo=ecgValuefloat;}

                        if(Globals.envio_permitido==1) {
                            Globals.lstPromedios.add(ecgValuefloat);
                            Globals.lstTiempoPromedio.add(Integer.parseInt(segundo));
                            Globals.lstSendContadorECG.add(cuenta);

                            new Handler().postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    ServiceManager2.onSendData();
                                }
                            },257);//Tiempo de retardo para empezar a enviar datos.
                        }
                        MainActivity.mECGWaveDraw.add(Integer.parseInt(valorECG));
                        break;

This is what marks me in android studio:

I/art: Clamp target GC heap from 112MB to 96MB
I/art: Alloc partial concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 96MB/96MB, paused 22.089ms total 294.317ms
I/art: WaitForGcToComplete blocked for 2.477s for cause Alloc
I/art: Alloc sticky concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 96MB/96MB, paused 1.410ms total 10.915ms
I/art: WaitForGcToComplete blocked for 2.335s for cause HeapTrim
W/art: Suspending all threads took: 21.596ms
I/art: WaitForGcToComplete blocked for 1.922s for cause Alloc
I/art: Clamp target GC heap from 112MB to 96MB
I/art: Alloc concurrent mark sweep GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 0% free, 96MB/96MB, paused 1.423ms total 291.358ms
I/art: WaitForGcToComplete blocked for 1.906s for cause Alloc
E/art: Throwing OutOfMemoryError "Failed to allocate a 28 byte allocation with 0 free bytes and 3GB until OOM" (recursive case)
E/art: "pool-1-thread-5" prio=5 tid=24 Runnable
E/art:   | group="main" sCount=0 dsCount=0 obj=0x22c08880 self=0xb7fee030
E/art:   | sysTid=31189 nice=0 cgrp=apps sched=0/0 handle=0xb8061450
E/art:   | state=R schedstat=( 0 0 0 ) utm=1033 stm=151 core=1 HZ=100
E/art:   | stack=0xa23b3000-0xa23b5000 stackSize=1036KB
E/art:   | held mutexes= "mutator lock"(shared held)
E/art:     at org.apache.http.conn.BasicManagedEntity.getContent(BasicManagedEntity.java:105)
E/art:     at com.loopj.android.http.AsyncHttpResponseHandler.getResponseData(unavailable:-1)
E/art:     at com.loopj.android.http.AsyncHttpResponseHandler.sendResponseMessage(unavailable:-1)
E/art:     at com.loopj.android.http.AsyncHttpRequest.makeRequest(unavailable:-1)
E/art:     at com.loopj.android.http.AsyncHttpRequest.makeRequestWithRetries(unavailable:-1)
E/art:     at com.loopj.android.http.AsyncHttpRequest.run(unavailable:-1)
E/art:     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
E/art:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
E/art:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
E/art:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
E/art:     at java.lang.Thread.run(Thread.java:818)
I/art: Clamp target GC heap from 112MB to 96MB
I/art: Alloc concurrent mark sweep GC freed 1(16B) AllocSpace objects, 0(0B) LOS objects, 0% free, 96MB/96MB, paused 1.317ms total 294.517ms
I/art: WaitForGcToComplete blocked for 2.157s for cause Alloc
W/art: Suspending all threads took: 249.580ms
W/art: Suspending all threads took: 19.680ms
E/art: Throwing OutOfMemoryError "Failed to allocate a 28 byte allocation with 0 free bytes and 3GB until OOM" (recursive case)
E/art: "main" prio=5 tid=1 Runnable
E/art:   | group="main" sCount=0 dsCount=0 obj=0x73007000 self=0xb7bce6d0
E/art:   | sysTid=27944 nice=0 cgrp=apps sched=0/0 handle=0xb6f19bec
E/art:   | state=R schedstat=( 0 0 0 ) utm=4883 stm=1409 core=1 HZ=100
E/art:   | stack=0xbe217000-0xbe219000 stackSize=8MB
E/art:   | held mutexes= "mutator lock"(shared held)
E/art:     at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:95)
E/art:     at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:146)
E/art:     at java.lang.StringBuilder.append(StringBuilder.java:216)
E/art:     at com.botonmedico.amunet.service.ServiceManager2.onSendData(ServiceManager2.java:250)
E/art:     at com.botonmedico.amunet.MainActivity$3$1.run(MainActivity.java:454)
E/art:     at android.os.Handler.handleCallback(Handler.java:739)
E/art:     at android.os.Handler.dispatchMessage(Handler.java:95)
E/art:     at android.os.Looper.loop(Looper.java:135)
E/art:     at android.app.ActivityThread.main(ActivityThread.java:5343)
E/art:     at java.lang.reflect.Method.invoke!(Native method)
E/art:     at java.lang.reflect.Method.invoke(Method.java:372)
E/art:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
E/art:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
I/art: Clamp target GC heap from 111MB to 96MB
I/art: Alloc partial concurrent mark sweep GC freed 121(44KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 20.869ms total 279.848ms
I/art: WaitForGcToComplete blocked for 2.170s for cause Alloc
I/art: WaitForGcToComplete blocked for 1.851s for cause Alloc
E/System: Uncaught exception thrown by finalizer
E/System: java.lang.OutOfMemoryError: Failed to allocate a 24 byte allocation with 0 free bytes and 3GB until OOM
              at com.android.internal.os.BinderInternal$GcWatcher.finalize(BinderInternal.java:51)
              at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:191)
              at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:174)
              at java.lang.Thread.run(Thread.java:818)
I/art: Clamp target GC heap from 111MB to 96MB
I/art: Alloc concurrent mark sweep GC freed 114(10KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 1.284ms total 285.480ms
I/art: WaitForGcToComplete blocked for 3.396s for cause Alloc
W/art: Suspending all threads took: 258.115ms
I/art: Clamp target GC heap from 111MB to 96MB
I/art: Alloc partial concurrent mark sweep GC freed 98(43KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 2.321ms total 290.789ms
I/art: WaitForGcToComplete blocked for 4.416s for cause Alloc
W/art: Suspending all threads took: 244.202ms
I/art: Clamp target GC heap from 111MB to 96MB
I/art: Alloc partial concurrent mark sweep GC freed 215(47KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 1.444ms total 277.432ms
I/art: WaitForGcToComplete blocked for 2.644s for cause Alloc
I/art: Clamp target GC heap from 111MB to 96MB
I/art: Alloc partial concurrent mark sweep GC freed 236(49KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 1.328ms total 308.473ms
I/art: WaitForGcToComplete blocked for 2.953s for cause Alloc
W/art: Suspending all threads took: 265.711ms

       --------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: Thread-593
                  Process: com.botonmedico.amunet, PID: 27944
                  java.lang.OutOfMemoryError: Failed to allocate a 24 byte allocation with 0 free bytes and 3GB until OOM
                      at com.botonmedico.amunet.wave.DrawRunnable.run(DrawRunnable.java:73)
                      at java.lang.Thread.run(Thread.java:818)
I/art: Clamp target GC heap from 111MB to 96MB
I/art: Alloc concurrent mark sweep GC freed 68(7KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 2.425ms total 298.383ms
I/art: WaitForGcToComplete blocked for 2.682s for cause Alloc
W/art: Suspending all threads took: 350.898ms
W/art: Suspending all threads took: 23.158ms
I/art: Clamp target GC heap from 111MB to 96MB
I/art: Alloc concurrent mark sweep GC freed 12(448B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 25.036ms total 394.020ms
I/art: WaitForGcToComplete blocked for 5.659s for cause Alloc
W/art: Suspending all threads took: 373.959ms
I/art: Clamp target GC heap from 111MB to 96MB
I/art: Alloc partial concurrent mark sweep GC freed 9(2384B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 2.556ms total 425.551ms
I/art: WaitForGcToComplete blocked for 3.218s for cause Alloc
W/art: Suspending all threads took: 331.176ms
W/art: Suspending all threads took: 21.698ms
I/art: Clamp target GC heap from 111MB to 96MB
I/art: Alloc concurrent mark sweep GC freed 197(48KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 23.694ms total 362.057ms
I/art: WaitForGcToComplete blocked for 3.515s for cause Alloc
W/art: Suspending all threads took: 13.080ms
I/art: Alloc sticky concurrent mark sweep GC freed 8(2320B) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 2.135ms total 14.007ms
I/art: WaitForGcToComplete blocked for 3.544s for cause Alloc
W/art: Suspending all threads took: 308.457ms
W/IdleConnectionHandler: Removing a connection that never existed!
W/System.err: java.io.IOException: File too large to fit into available memory
W/System.err:     at com.loopj.android.http.AsyncHttpResponseHandler.getResponseData(Unknown Source)
W/System.err:     at com.loopj.android.http.AsyncHttpResponseHandler.sendResponseMessage(Unknown Source)
W/System.err:     at com.loopj.android.http.AsyncHttpRequest.makeRequest(Unknown Source)
W/System.err:     at com.loopj.android.http.AsyncHttpRequest.makeRequestWithRetries(Unknown Source)
W/System.err:     at com.loopj.android.http.AsyncHttpRequest.run(Unknown Source)
W/System.err:     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
W/System.err:     at java.lang.Thread.run(Thread.java:818)
W/System.err: java.io.IOException: File too large to fit into available memory
W/System.err:     at com.loopj.android.http.AsyncHttpResponseHandler.getResponseData(Unknown Source)
W/System.err:     at com.loopj.android.http.AsyncHttpResponseHandler.sendResponseMessage(Unknown Source)
W/System.err:     at com.loopj.android.http.AsyncHttpRequest.makeRequest(Unknown Source)
W/System.err:     at com.loopj.android.http.AsyncHttpRequest.makeRequestWithRetries(Unknown Source)
W/System.err:     at com.loopj.android.http.AsyncHttpRequest.run(Unknown Source)
W/System.err:     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
W/System.err:     at java.lang.Thread.run(Thread.java:818)
I/art: Clamp target GC heap from 111MB to 96MB
I/art: Alloc partial concurrent mark sweep GC freed 215(54KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 95MB/96MB, paused 2.114ms total 347.611ms
I/art: WaitForGcToComplete blocked for 3.583s for cause Alloc
I/art: WaitForGcToComplete blocked for 3.041s for cause Alloc
I/art: WaitForGcToComplete blocked for 19.112ms for cause Explicit
W/art: Suspending all threads took: 271.340ms
I/Process: Sending signal. PID: 27944 SIG: 9
Disconnected from the target VM, address: 'localhost:8600', transport: 'socket'

Could someone help me solve this problem? Thank you in advance.

    
asked by Xavi 30.03.2017 в 02:21
source

0 answers