Issus in memory management with json object

I have a problem with memory management in "Odoo_database_json" when I sync from the odoo server as it receives a huge JSON object from the odoo server that includes the image which gives me an in-memory error.

I've tried things like garbage collection, memory pruning, and raster transform ().

public class Databasetask extends AsyncTask<Void, Void, Void> {

    @Override
    protected Void doInBackground(Void... params) {
        // TODO Auto-generated method stub

        try {
            Odoo o = new Odoo("http://10.0.2.2:8089");
            JSONArray database_list = o.getDatabaseList();
            Log.e("database_list.", database_list.toString());

            // Log.e("qqqqqqqqqq.", j1.toString());
            o.authenticate("admin", "a", "demo");// =========>aa set karvanu
            // che

            JSONArray fields = new JSONArray();
            fields.put("city");
            fields.put("name");
            fields.put("phone");
            fields.put("image");
            fields.put("create_date");
            fields.put("write_date");

            // android.os.Debug.dumpHprofData("com.serpentcs.AIOS8.hprof");
            // Debug.dumpHprofData("com.serpentcs.AIOS8.hprof");
            // System.gc();

            JSONObject jsonParams = new JSONObject();
            jsonParams.put("fields", fields);

            // Odoo_database_json=null;
            //==================================================================Error at here because of heap momory is full when i sync data from Odoo server
            Odoo_database_json = o.search_read(Modle, jsonParams); //<==error at here

            jsonArray_items = Odoo_database_json.getJSONArray("records");

            // int x = TRIM_MEMORY_COMPLETE;
            // Log.e("x....",""+x);

            // table exxist ...if u change filed pls..remove it
            tableExist = exists("res_partner");
            Log.e("table", "" + tableExist);
            // if exist does not create table
            if (tableExist) {
                Log.e("Log.....", "Table is exist");

            } else {
                Log.e("Log.....", "Table is not exist");
                JSONObject a = jsonArray_items.getJSONObject(1);

                Iterator<?> key_fields = a.keys();// ===givs fields

                myhelper = new OdooHelper(Listview_contect.this);
                myhelper.makeTable(key_fields);

            }

            // // ==get the records and put it into database..
            //
            publishProgress();
            // //uncaughtException
            // // Log.e("qqqqqqqqqq.", "fgh");

        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (OVersionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (OutOfMemoryError e) {
            // TODO: handle exception
            e.printStackTrace();
        }

      

........................... sorry i don't know how to add new code because i m new..user..pls any edits it.

 10-30 13:14:50.692: E/dalvikvm-heap(1419): Out of memory on a 2097168-byte allocation.
10-30 13:14:50.692: I/dalvikvm(1419): "AsyncTask #1" prio=5 tid=11 RUNNABLE
10-30 13:14:50.692: I/dalvikvm(1419):   | group="main" sCount=0 dsCount=0 obj=0xb4e89628 self=0xb767e758
10-30 13:14:50.692: I/dalvikvm(1419):   | sysTid=1435 nice=10 sched=0/0 cgrp=apps/bg_non_interactive handle=-1217926224
10-30 13:14:50.702: I/dalvikvm(1419):   | state=R schedstat=( 22190000000 5900000000 5215 ) utm=2068 stm=151 core=0
10-30 13:14:50.702: I/dalvikvm(1419):   at java.util.Scanner.expandBuffer(Scanner.java:~2067)
10-30 13:14:50.702: I/dalvikvm(1419):   at java.util.Scanner.readMore(Scanner.java:2031)
10-30 13:14:50.702: I/dalvikvm(1419):   at java.util.Scanner.findDelimiterAfter(Scanner.java:2009)
10-30 13:14:50.702: I/dalvikvm(1419):   at java.util.Scanner.setTokenRegion(Scanner.java:1923)
10-30 13:14:50.702: I/dalvikvm(1419):   at java.util.Scanner.hasNext(Scanner.java:541)
10-30 13:14:50.702: I/dalvikvm(1419):   at java.util.Scanner.hasNext(Scanner.java:519)
10-30 13:14:50.702: I/dalvikvm(1419):   at odoo.Odoo.convertStreamToString(Odoo.java:1140)
10-30 13:14:50.702: I/dalvikvm(1419):   at odoo.Odoo.requestData(Odoo.java:460)
10-30 13:14:50.702: I/dalvikvm(1419):   at odoo.Odoo.search_read(Odoo.java:726)
10-30 13:14:50.702: I/dalvikvm(1419):   at odoo.Odoo.search_read(Odoo.java:771)
10-30 13:14:50.702: I/dalvikvm(1419):   at com.serpentcs.client.Listview_contect$Databasetask.doInBackground(Listview_contect.java:188)
10-30 13:14:50.702: I/dalvikvm(1419):   at com.serpentcs.client.Listview_contect$Databasetask.doInBackground(Listview_contect.java:1)
10-30 13:14:50.702: I/dalvikvm(1419):   at android.os.AsyncTask$2.call(AsyncTask.java:288)
10-30 13:14:50.702: I/dalvikvm(1419):   at java.util.concurrent.FutureTask.run(FutureTask.java:237)
10-30 13:14:50.702: I/dalvikvm(1419):   at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
10-30 13:14:50.712: I/dalvikvm(1419):   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
10-30 13:14:50.712: I/dalvikvm(1419):   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
10-30 13:14:50.712: I/dalvikvm(1419):   at java.lang.Thread.run(Thread.java:841)
10-30 13:14:50.712: W/System.err(1419): java.lang.OutOfMemoryError
10-30 13:14:50.712: W/System.err(1419):     at java.util.Scanner.expandBuffer(Scanner.java:2067)
10-30 13:14:50.722: W/System.err(1419):     at java.util.Scanner.readMore(Scanner.java:2031)
10-30 13:14:50.722: W/System.err(1419):     at java.util.Scanner.findDelimiterAfter(Scanner.java:2009)
10-30 13:14:50.722: W/System.err(1419):     at java.util.Scanner.setTokenRegion(Scanner.java:1923)
10-30 13:14:50.722: W/System.err(1419):     at java.util.Scanner.hasNext(Scanner.java:541)
10-30 13:14:50.732: W/System.err(1419):     at java.util.Scanner.hasNext(Scanner.java:519)
10-30 13:14:50.732: W/System.err(1419):     at odoo.Odoo.convertStreamToString(Odoo.java:1140)
10-30 13:14:50.732: W/System.err(1419):     at odoo.Odoo.requestData(Odoo.java:460)
10-30 13:14:50.732: W/System.err(1419):     at odoo.Odoo.search_read(Odoo.java:726)
10-30 13:14:50.732: W/System.err(1419):     at odoo.Odoo.search_read(Odoo.java:771)
10-30 13:14:50.732: W/System.err(1419):     at com.serpentcs.client.Listview_contect$Databasetask.doInBackground(Listview_contect.java:188)
10-30 13:14:50.732: W/System.err(1419):     at com.serpentcs.client.Listview_contect$Databasetask.doInBackground(Listview_contect.java:1)
10-30 13:14:50.732: W/System.err(1419):     at android.os.AsyncTask$2.call(AsyncTask.java:288)
10-30 13:14:50.732: W/System.err(1419):     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
10-30 13:14:50.732: W/System.err(1419):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
10-30 13:14:50.732: W/System.err(1419):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
10-30 13:14:50.732: W/System.err(1419):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
10-30 13:14:50.732: W/System.err(1419):     at java.lang.Thread.run(Thread.java:841)    

      

+3


source to share





All Articles