4 Replies Latest reply: Apr 24, 2017 9:12 AM by tavor.jeremic RSS

Application chrush (out of memmory) with bb sdk plugin installed

tavor.jeremic Newbie

Hi,

I have cordova application that is getting data from a REST server.

Without bb plugins it works without problems, but with the plugins it crashed when I tried to download 57959 records (around 35MB of data in JSON format) from the REST.


Used plugins are:

cordova-plugin-bbd-base 1.0.0 "Base Plugin"

cordova-plugin-bbd-httprequest 1.0.0 "HttpRequest Plugin"

cordova-plugin-bbd-storage 1.0.0 "Storage Plugin"

cordova-plugin-bbd-xmlhttprequest 1.0.0 "XmlHttpRequest Plugin"


Log output is:

04-21 14:08:00.364 13184-13367/com.test.testapp I/art: Starting a blocking GC Alloc

04-21 14:08:00.377 13184-13367/com.test.testapp I/art: Alloc concurrent mark sweep GC freed 5(120B) AllocSpace objects, 0(0B) LOS objects, 9% free, 144MB/160MB, paused 274us total 12.781ms

04-21 14:08:00.377 13184-13367/com.test.testapp I/art: Starting a blocking GC HomogeneousSpaceCompact

04-21 14:08:00.396 13184-13367/com.test.testapp I/art: HomogeneousSpaceCompact marksweep + semispace GC freed 0(0B) AllocSpace objects, 0(0B) LOS objects, 9% free, 144MB/160MB, paused 18.298ms total 18.298ms

04-21 14:08:00.396 13184-13367/com.test.testapp W/art: Throwing OutOfMemoryError "Failed to allocate a 150994952 byte allocation with 16773216 free bytes and 111MB until OOM"

                                                              

                                                               --------- beginning of crash

04-21 14:08:00.399 13184-13367/com.test.testapp E/AndroidRuntime: FATAL EXCEPTION: pool-1-thread-2

                                                                          Process: com.test.testapp, PID: 13184

                                                                          java.lang.OutOfMemoryError: Failed to allocate a 150994952 byte allocation with 16773216 free bytes and 111MB until OOM

                                                                              at java.util.Arrays.copyOf(Arrays.java:3352)

                                                                              at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:130)

                                                                              at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:114)

                                                                              at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:606)

                                                                              at java.lang.StringBuilder.append(StringBuilder.java:215)

                                                                              at org.json.JSONStringer.string(JSONStringer.java:344)

                                                                              at org.json.JSONStringer.value(JSONStringer.java:252)

                                                                              at org.json.JSONObject.writeTo(JSONObject.java:720)

                                                                              at org.json.JSONObject.toString(JSONObject.java:689)

                                                                              at com.good.gd.cordova.plugins.helpers.GDHttpRequestPluginHelper.sendFinalSuccessPluginResult(GDHttpRequestPluginHelper.java:35)

                                                                              at com.good.gd.cordova.plugins.GDXmlHttpRequestPlugin.executeRequest(GDXmlHttpRequestPlugin.java:231)

                                                                              at com.good.gd.cordova.plugins.GDXmlHttpRequestPlugin.access$200(GDXmlHttpRequestPlugin.java:84)

                                                                              at com.good.gd.cordova.plugins.GDXmlHttpRequestPlugin$2.run(GDXmlHttpRequestPlugin.java:188)

                                                                              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)

                                                                              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)

                                                                              at java.lang.Thread.run(Thread.java:761)

  • Re: Application chrush (out of memmory) with bb sdk plugin installed
    ctetreault BlackBerry Employee

    Hi there,

     

    Could you briefly explain your use-case for downloading this much JSON data into memory? Is it to display all this data in a list view, or? All programming/frameworks/SDKs aside, there is likely another approach for what's being attempted that will result in less memory usage.

    • Re: Application chrush (out of memmory) with bb sdk plugin installed
      tavor.jeremic Newbie

      Hi,

      The use case is database synchronization. The data received would be stored on the device.

      This is initial load of data. It is required for offline capabilities.

      • Re: Application chrush (out of memmory) with bb sdk plugin installed
        ctetreault BlackBerry Employee

        Ok thank you. I think in this case it may be best to have logic that would allow you to download the JSON payload in chunks. There's typically a server side aspect to this as well.

         

        A couple of things to keep in mind from my past experience:

         

        - Consider is the (potential) data usage for the users downloading this initially. For example if 1,000 ppl run the app for the first time and are not on wifi then the company could be paying for 1,000 x 35meg of data for the first run of this application. Not to say this isn't a valid use-case, just something to be aware of is all

         

        - Lastly, if you're having to manipulate filter/map all this data in the app you may have a bad experience memory wise/performance wise. This is not unique to BBD, this is just the nature of web development. In an ideal situation you will want this data coming to the application already formatted in a way your app can use.

        • Re: Application chrush (out of memmory) with bb sdk plugin installed
          tavor.jeremic Newbie

          Thank you for your reply.

          We have in mind potential data usage for the full load.

          Regarding performance - we have tested loading, storing and filtering large amounts of data (without using bb sdk) and results were fine.

           

          So is there any limitation in the sdk to the amount of data it can handle in one request?

          Is the crash bug in the sdk - should it not be handled somehow (like maybe returning error instead of crashing application)?