开发者

Problem in loading large strings in the memory

I have problem in loading large strings in the memory. I have a WebService that returns a string. Sometimes the size of this string is huge about 4MB.

My Code:

... 
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
envelope.dotNet = true;

envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(url);

androidHttpTransport.call(soapAction, envelope);

When the size of string is huge, the program stops unexpectedly at the end line with no exceptions.

what should I do to resolve this issue?


Edit: error log:

09-12 09:20:19.790: INFO/dalvikvm-heap(3515): Grow heap (frag case) to 12.845MB for 3319472-byte allocation
09-12 09:20:19.850: DEBUG/dalvikvm(3515): GC_CONCURRENT freed 0K, 8% free 13093K/14151K, paused 3ms+2ms
09-12 09:20:28.510: DEBUG/PowerManagerService(136): @PowerManagement: Auto-dim timeout
09-12 09:20:28.510: DEBUG/PowerManagerService(136): @PowerManagement: Screen Bright {true -> false}
09-12 09:20:38.330: DEBUG/dalvikvm(3515): GC_FOR_ALLOC freed 2179K, 23% free 10932K/14151K, paused 42ms
09-12 09:20:38.340: INFO/dalvikvm-heap(3515): Grow heap (frag case) to 15.484MB for 4979204-byte allocation
09-12 09:20:38.390: DEBUG/dalvikvm(3515): GC_CONCURRENT freed 0K, 17% free 15794K/19015K, paused 2ms+3ms
09-12 09:20:59.920: DEBUG/DockManagerService(136): Display mobile dock notificaiton, level:5 status:4
09-12 09:20:59.920: DEBUG/BatteryService(136): level:99 scale:100 status:2 health:2 present:true dock_status:4 dock_level:5 voltage: 8 temperature: 270 technology: Li-ion AC powered:true USB powered:false icon:17302732 invalid charger:0
09-12 09:20:59.930: INFO/fdhttpd(3345): battery level:99 plugged:1
09-12 09:20:59.930: DEBUG/PowerUI(184): closing low battery warning: level=99
09-12 09:21:05.070: DEBUG/dalvikvm(223): GC_EXPLICIT freed 1K, 33% free 21283K/31431K, paused 4ms+3ms
09-12 09:21:12.440: DEBUG/dalvikvm(3515): GC_FOR_ALLOC freed 3267K, 34% free 12553K/19015K, paused 31ms
09-12 09:21:12.450: INFO/dalvikvm-heap(3515): Grow heap (frag case) to 19.441MB for 7468802-byte allocation
09-12 09:21:12.560: DEBUG/dalvikvm(3515): GC_CONCURRENT freed 0K, 25% free 19846K/26311K, paused 2ms+2ms
09-12 09:21:59.380: DEBUG/dalvikvm(3515): GC_FOR_ALLOC freed 4902K, 44% free 14984K/26311K, paused 37ms
09-12 09:21:59.400: INFO/dalvikvm-heap(3515): Grow heap (frag case) to 25.376MB for 11203198-byte allocation
09-12 09:21:59.490: DEBUG/dalvikvm(3515): GC_FOR_ALLOC freed 0K, 31% free 25925K/37255K, paused 26ms
09-12 09:21:59.540: DEBUG/dalvikvm(3515): GC_CONCURRENT freed 7293K, 50% free 18631K/37255K, paused 2ms+3ms
09-12 09:22:39.230: ERROR/MPL-accel(136): ../../accel.c|AccelGetData|144 returning 146
09-12 09:22:39.230: ERROR/MPL-fifo(136): ../../mlFIFO.c|readAndProcessFIFO|569 returning 146
09-12 09:22:39.230: ERROR/MPL-ml(136): ../../ml.c|MLUpdateData|763 returning 146
09-12 09:22:39.230: ERROR/Sensors(136): MLUpdateData error (code 146)
09-12 09:23:00.230: DEBUG/BatteryService(136): level:99 scale:100 status:2 health:2 present:true dock_status:4 dock_level:4 voltage: 8 temperature: 269 technology: Li-ion AC powered:true USB powered:false icon:17302732 invalid charger:0
09-12 09:23:00.240: DEBUG/DockManagerService(136): Display mobile dock notificaiton, level:4 status:4
09-12 09:23:00.240: INFO/fdhttpd(3345): battery level:99 plugged:1
09-12 09:23:00.240: DEBUG/PowerUI(184): closing low battery warning: level=99
09-12 09:23:05.300: DEBUG/dalvikvm(223): GC_EXPLICIT freed 1K, 33% free 21283K/31431K, paused 8ms+3ms
09-12 09:23:08.620: DEBUG/dalvikvm(3515): GC_FOR_ALLOC freed 59K, 50% free 18631K/37255K, paused 33ms
09-12 09:23:08.620: INFO/dalvikvm-heap(3515): Forcing collection of SoftReferences for 16804792-byte allocation
09-12 09:23:08.650: DEBUG/dalvikvm(3515): GC_BEFORE_OOM freed 8K, 51% free 18622K/37255K, paused 28ms
09-12 09:23:08.650: ERROR/dalvikvm-heap(3515): Out of memory on a 16804792-byte allocation.
09-12 09:23:08.650: INFO/dalvikvm(3515): "Thread-11" prio=5 tid=10 RUNNABLE
09-12 09:23:08.650: INFO/dalvikvm(3515):   | group="main" sCount=0 dsCount=0 obj=0x4085c4b0 self=0x172650
09-12 09:23:08.650: INFO/dalvikvm(3515):   | sysTid=3558 nice=0 sched=0/0 cgrp=default handle=1831224
09-12 09:23:08.650: INFO/dalvikvm(3515):   | schedstat=( 4096840000 1017805000 13067 ) utm=332 stm=77 core=1
09-12 09:23:08.650: INFO/dalvikvm(3515):   at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:~96)
09-12 09:23:08.650: INFO/dalvikvm(3515):   at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:126)
09-12 09:23:08.650: INFO/dalvikvm(3515):   at java.lang.StringBuilder.append(StringBuilder.java:272)
09-12 09:23:08.650: INFO/dalvikvm(3515):   at org.kxml2.io.KXmlParser.readValue(KXmlParser.java:1338)
09-12 09:23:08.650: INFO/dalvikvm(3515):   at org.kxml2.io.KXmlParser.next(KXmlParser.java:390)
09-12 09:23:08.650: INFO/dalvikvm(3515):   at org.kxml2.io.KXmlParser.next(KXmlParser.java:310)
09-12 09:23:08.650: INFO/dalvikvm(3515):   at org.ksoap2.serialization.SoapSerializationEnvelope.readUnknown(SoapSerializationEnvelope.java:233)
09-12 09:23:08.650: INFO/dalvikvm(3515):   at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:404)
09-12 09:23:08.650: INFO/dalvikvm(3515):   at org.ksoap2.serialization.SoapSerializationEnvelope.readUnknown(SoapSerializationEnvelope.java:271)
09-12 09:23:08.650: INFO/dalvikvm(3515):   at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:404)
09-12 09:23:08.650: INFO/dalvikvm(3515):   at org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(SoapSerializationEnvelope.java:131)
09-12 09:23:08.650: INFO/dalvikvm(3515):   at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:137)
09-12 09:23:08.650: INFO/dalvikvm(3515):   at org.ksoap2.transport.Transport.parseResponse(Transport.java:90)
09-12 09:23:08.650: INFO/dalvikvm(3515):   at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:179)
09-12 09:23:08.650: INFO/dalvikvm(3515):   at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:90)
09-12 09:23:08.650: INFO/dalvikvm(3515):   at org.mabna.order.ui.ActToolDataExchange.threadGetFiles(ActToolDataExchange.java:185)
09-12 09:23:08.650: INFO/dalvikvm(3515):   at org.mabna.order.ui.ActToolDataExchange.access$3(ActToolDataExchange.java:145)
09-12 09:23:08.650: INFO/dalvikvm(3515):   at org.mabna.order.ui.ActToolDataExchange$6.run(ActToolDataExchange.java:134)
09-12 09:23:08.650: INFO/dalvikvm(3515):   at org.mabna.order.utils.Utilities$5.run(Utilities.java:718)
09-12 09:23:08.650: WARN/dalvikvm(3515): threadid=10: thread exiting with uncaught exception (group=0x401c4760)
09-12 09:23:08.660: ERROR/AndroidRuntime(3515): FATAL EXCEPTION: Thread-11
09-12 09:23:08.660: ERROR/AndroidRuntime(3515): java.lang.OutO开发者_开发百科fMemoryError
09-12 09:23:08.660: ERROR/AndroidRuntime(3515):     at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:96)
09-12 09:23:08.660: ERROR/AndroidRuntime(3515):     at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:126)
09-12 09:23:08.660: ERROR/AndroidRuntime(3515):     at java.lang.StringBuilder.append(StringBuilder.java:272)
09-12 09:23:08.660: ERROR/AndroidRuntime(3515):     at org.kxml2.io.KXmlParser.readValue(KXmlParser.java:1338)
09-12 09:23:08.660: ERROR/AndroidRuntime(3515):     at org.kxml2.io.KXmlParser.next(KXmlParser.java:390)
09-12 09:23:08.660: ERROR/AndroidRuntime(3515):     at org.kxml2.io.KXmlParser.next(KXmlParser.java:310)
09-12 09:23:08.660: ERROR/AndroidRuntime(3515):     at org.ksoap2.serialization.SoapSerializationEnvelope.readUnknown(SoapSerializationEnvelope.java:233)
09-12 09:23:08.660: ERROR/AndroidRuntime(3515):     at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:404)


Not an android master, so I may be getting a few down votes for this answer.

You say you have a web service which returns a string, so essentially you're downloading 4mb of data and loading it. Your problem here may well be the speed that your android device can download/upload data at. Have you tried running this on a real device and watching the LogCat window? It could be that the network request is causing your main thread to timeout.

To verify this, you could try manually setting a variable with an example response that you may get from the server. String str = "abcd... If that crashes your application then I'm not sure. But if that works then it may well be your network request causing a timeout.

To solve a network request timeout, what you should actually do is run the network request in a separate thread. Examples can be found on the Android Dev site.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜