Note that there are some explanatory texts on larger screens.

plurals
  1. POJSONObject toString() causes Out Of Memory on a 1495472-byte allocation
    text
    copied!<p>I am using the following device to test my app:</p> <p><img src="https://i.stack.imgur.com/QKmic.png" alt="enter image description here"></p> <p>I am posting a JSON string that is about 498467 bytes (0.48MB) in size. </p> <p>When my app syncs this data, it fails when I <code>toString()</code> the <code>JSONObect</code> e.g:</p> <pre><code>JSONObject jsonObj = new JSONObject(); ... ClientMyAppApi.Upload(getContext(), account.name, jsonObj.toString()); // Out of memory here </code></pre> <p>Here is the LogCat transcript:</p> <pre><code>D/dalvikvm(21964): GC_CONCURRENT freed 690K, 12% free 10892K/12295K, paused 5ms+9ms D/dalvikvm(21964): GC_FOR_ALLOC freed 606K, 9% free 11196K/12295K, paused 57ms I/dalvikvm-heap(21964): Grow heap (frag case) to 11.630MB for 662266-byte allocation D/dalvikvm(21964): GC_FOR_ALLOC freed 431K, 13% free 11411K/12999K, paused 61ms I/dalvikvm-heap(21964): Grow heap (frag case) to 12.157MB for 993394-byte allocation D/dalvikvm(21964): GC_FOR_ALLOC freed 646K, 17% free 11734K/14023K, paused 63ms I/dalvikvm-heap(21964): Grow heap (frag case) to 12.947MB for 1490086-byte allocation D/dalvikvm(21964): GC_FOR_ALLOC freed 970K, 22% free 12220K/15495K, paused 69ms D/AdapterSync(21964): uploadNewContent() JSON request size: 498468 D/dalvikvm(21964): GC_CONCURRENT freed 3172K, 30% free 10892K/15495K, paused 5ms+26ms D/dalvikvm(21964): GC_FOR_ALLOC freed 606K, 28% free 11195K/15495K, paused 56ms D/dalvikvm(21964): GC_FOR_ALLOC freed 431K, 27% free 11411K/15495K, paused 59ms D/dalvikvm(21964): GC_FOR_ALLOC freed 646K, 25% free 11734K/15495K, paused 61ms D/dalvikvm(21964): GC_FOR_ALLOC freed 970K, 22% free 12219K/15495K, paused 69ms D/dalvikvm(21964): GC_FOR_ALLOC freed 1459K, 25% free 11742K/15495K, paused 74ms D/dalvikvm(21964): GC_CONCURRENT freed 664K, 18% free 12726K/15495K, paused 17ms+12ms D/dalvikvm(21964): GC_CONCURRENT freed 1930K, 18% free 12723K/15495K, paused 22ms+10ms D/dalvikvm(21964): GC_FOR_ALLOC freed 13K, 18% free 12716K/15495K, paused 70ms I/dalvikvm-heap(21964): Forcing collection of SoftReferences for 1495472-byte allocation D/dalvikvm(21964): GC_BEFORE_OOM freed 9K, 18% free 12707K/15495K, paused 114ms E/dalvikvm-heap(21964): Out of memory on a 1495472-byte allocation. I/dalvikvm(21964): "SyncAdapterThread-1" prio=5 tid=20 RUNNABLE I/dalvikvm(21964): | group="main" sCount=0 dsCount=0 obj=0x4101ac78 self=0x2f5198 I/dalvikvm(21964): | sysTid=22098 nice=10 sched=0/0 cgrp=bg_non_interactive handle=3325456 I/dalvikvm(21964): | schedstat=( 5787106417 2132935545 325 ) utm=552 stm=26 core=0 I/dalvikvm(21964): at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:~94) I/dalvikvm(21964): at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:132) I/dalvikvm(21964): at java.lang.StringBuilder.append(StringBuilder.java:124) I/dalvikvm(21964): at libcore.net.UriCodec.appendEncoded(UriCodec.java:119) I/dalvikvm(21964): at libcore.net.UriCodec.encode(UriCodec.java:133) I/dalvikvm(21964): at java.net.URLEncoder.encode(URLEncoder.java:57) I/dalvikvm(21964): at org.apache.http.client.utils.URLEncodedUtils.encode(URLEncodedUtils.java:184) I/dalvikvm(21964): at org.apache.http.client.utils.URLEncodedUtils.format(URLEncodedUtils.java:163) I/dalvikvm(21964): at org.apache.http.client.entity.UrlEncodedFormEntity.&lt;init&gt;(UrlEncodedFormEntity.java:57) I/dalvikvm(21964): at com.myapp.utils.NetworkUtils.makeHttpRequestWithParams(NetworkUtils.java:177) I/dalvikvm(21964): at com.myapp.client.ClientMyAppApi.MakeRequest(ClientMyAppApi.java:208) I/dalvikvm(21964): at com.myapp.client.ClientMyAppApi.Upload(ClientMyAppApi.java:395) I/dalvikvm(21964): at com.myapp.syncadapter.AdapterSync.uploadNewContent(AdapterSync.java:744) I/dalvikvm(21964): at com.myapp.syncadapter.AdapterSync.onPerformSync(AdapterSync.java:120) I/dalvikvm(21964): at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:247) W/dalvikvm(21964): threadid=20: thread exiting with uncaught exception (group=0x409c01f8) E/AndroidRuntime(21964): FATAL EXCEPTION: SyncAdapterThread-1 E/AndroidRuntime(21964): java.lang.OutOfMemoryError E/AndroidRuntime(21964): at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:94) E/AndroidRuntime(21964): at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:132) E/AndroidRuntime(21964): at java.lang.StringBuilder.append(StringBuilder.java:124) E/AndroidRuntime(21964): at libcore.net.UriCodec.appendEncoded(UriCodec.java:119) E/AndroidRuntime(21964): at libcore.net.UriCodec.encode(UriCodec.java:133) E/AndroidRuntime(21964): at java.net.URLEncoder.encode(URLEncoder.java:57) E/AndroidRuntime(21964): at org.apache.http.client.utils.URLEncodedUtils.encode(URLEncodedUtils.java:184) E/AndroidRuntime(21964): at org.apache.http.client.utils.URLEncodedUtils.format(URLEncodedUtils.java:163) E/AndroidRuntime(21964): at org.apache.http.client.entity.UrlEncodedFormEntity.&lt;init&gt;(UrlEncodedFormEntity.java:57) E/AndroidRuntime(21964): at com.myapp.utils.NetworkUtils.makeHttpRequestWithParams(NetworkUtils.java:177) E/AndroidRuntime(21964): at com.myapp.client.ClientMyAppApi.MakeRequest(ClientMyAppApi.java:208) E/AndroidRuntime(21964): at com.myapp.client.ClientMyAppApi.Upload(ClientMyAppApi.java:395) E/AndroidRuntime(21964): at com.myapp.syncadapter.AdapterSync.uploadNewContent(AdapterSync.java:744) E/AndroidRuntime(21964): at com.myapp.syncadapter.AdapterSync.onPerformSync(AdapterSync.java:120) E/AndroidRuntime(21964): at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:247) </code></pre> <p>What and how is the best way to fix this out of memory issue?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload