OutOfMemoryError for a periodic request

2,204 views
Skip to first unread message

Markus Bodmann

unread,
May 3, 2015, 9:16:46 AM5/3/15
to volley...@googlegroups.com
Hello,

I make this request every 30 sec:

    public void checkLight(){
        RequestQueue queue = Volley.newRequestQueue(mContext);
        JsonObjectRequest jsObjRequest = new JsonObjectRequest (Request.Method.GET, "http://mediaserver:8083/fhem?cmd=jsonlist2%20WZ.Licht1&XHR=1", null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                try {
                    String statValue = response.getJSONArray("Results").getJSONObject(0).getJSONObject("Readings").getJSONObject("state").getString("Value");
                    switch (statValue){
                        case "off":
                            lightStatus = false;
                            break;
                        case "on":
                            lightStatus = true;
                            break;
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {}
        });
        queue.add(jsObjRequest);
    }

After a while my App crash with this error:

05-03 15:02:08.582      717-717/de.resper.autoheim W/libc﹕ pthread_create failed: couldn't allocate 1064960-byte stack: Out of memory
05-03 15:02:08.588      717-717/de.resper.autoheim E/art﹕ Throwing OutOfMemoryError "pthread_create (1040KB stack) failed: Try again"
05-03 15:02:08.590      717-717/de.resper.autoheim D/AndroidRuntime﹕ Shutting down VM
05-03 15:02:08.598      717-717/de.resper.autoheim E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: de.resper.autoheim, PID: 717
    java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Try again
            at java.lang.Thread.nativeCreate(Native Method)
            at java.lang.Thread.start(Thread.java:1063)
            at com.android.volley.RequestQueue.start(RequestQueue.java:152)
            at com.android.volley.toolbox.Volley.newRequestQueue(Volley.java:66)
            at com.android.volley.toolbox.Volley.newRequestQueue(Volley.java:78)
            at de.resper.autoheim.controls.CtrlWz.checkLight(CtrlWz.java:46)
            at de.resper.autoheim.WohnzimmerActivity$1.run(WohnzimmerActivity.java:43)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
05-03 15:03:38.396      717-717/de.resper.autoheim I/Process﹕ Sending signal. PID: 717 SIG: 9



The Line:
at de.resper.autoheim.controls.CtrlWz.checkLight(CtrlWz.java:46)

is this line in the code:

RequestQueue queue = Volley.newRequestQueue(mContext);


Ficus Kirkpatrick

unread,
May 3, 2015, 1:58:22 PM5/3/15
to Markus Bodmann, volley...@googlegroups.com
Probably goes away if you stop making a new RQ every 30 seconds and just reuse one.

--
You received this message because you are subscribed to the Google Groups "Volley Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to volley-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hari Shankar S

unread,
Aug 5, 2019, 5:16:32 AM8/5/19
to Volley Users
same problem i faced when new RequestQueue for every request. that's the reason I suspect it was throwing the OutOfMemory Exception. The solution is 

instead of RequestQueue requestQueue = Volley.newRequestQueue(context);

declare the RequestQueue outside the method and add a new RequestQueue only if the previous one is null.

private RequestQueue requestQueue;

public void yourFunction() {

    try{

if (requestQueue == null) {
        requestQueue = Volley.newRequestQueue(context);
        //your code
  } 
  
     }catch(Exception e){
            Log.d(e.getMessage().toString());
     }
}

....................................................
Reply all
Reply to author
Forward
0 new messages