Export to GitHub

ksoap2-android - issue #137

OutOfMemory if response is huge


Posted on Oct 3, 2012 by Swift Giraffe

What steps will reproduce the problem? If response from server is huge, android device gives OutOfMemory Error

What version of the product are you using? On what operating system? ksoap 2.6.5 on Mac OSX Lion 10.7.3

Please provide any additional information below.

All data downloaded are saved on memory, so if xml response is huge any device can give this error. One possible solution can be giving possibility to save data directly on disk as an xml file for example.

Comment #1

Posted on Oct 10, 2012 by Swift Hippo

If the file is to big to be parsed from the network when it is sent it would also be too big to be parsed from disk so what would be the point of saving the xml?

If you xml response is too large you should refactor the webservice to support paged data or find some other way to reduce the response size imho.

Comment #2

Posted on Oct 10, 2012 by Swift Giraffe

It's not true. If i can save the xml file on disk, i can read it depending on free VM space available. So, if data are huge, i can, for example, split it in multiple file and read and parse one mini-file time by time and then clear memory every time i finished to parse it, and go to second one doing the same. However i solved the problem modifying by myself HTTPtransportSE file by introducing a static boolean by which i can choose if to save directly on VM memory (default behaviour) or if to save on disk

Comment #3

Posted on Oct 10, 2012 by Swift Hippo

Fair enough. Care to share that improvement with the rest of us as a patch or pull request?

Comment #4

Posted on Oct 10, 2012 by Swift Giraffe

I left how i implemented code here:

http://stackoverflow.com/questions/4941581/very-large-soap-response-android-out-of-memory-error/12732396#12732396

Look for kinghomer's response (it's me).

Comment #5

Posted on Oct 10, 2012 by Swift Hippo

I think It would be feasible to implement this as an alternative storing the xml where the File is passed into the transport in the constructor or as a parameter with some sort of flag that triggers the saving of the xml file. I will take a pull request if you send one ;-)

Comment #6

Posted on Nov 12, 2012 by Swift Hippo

I have implemented this in master now. Please try it and let me know if that works for you.

Comment #7

Posted on Nov 13, 2012 by Happy Kangaroo

I think this issue is more deeper than just OOM raised because of huge response. Sometimes I caught OOM exceptions. But it looks very strange. For example, I request 10M response from server and all is OK. After that I KILL application and start it and request 10M again and so on. In this test case I will receive OOM exception after iteration 5 or more.

My be it should be interpreted as memory leak in Android?

Comment #8

Posted on Nov 13, 2012 by Swift Giraffe

I think problem is that memory is not cleaned as well after data is consumed. I put in HttpTransportSE class file a call to these functions:

arrayOfDataDownloaded = null; System.gc();

By this call i solved that problem. Btw, problem is always huge response. Every device dedicates a specific and equal amount of Memory for each application. For example, S3 dedicates 48Mb-Ram foreach App because has 1gb Ram memory. Another device that has 512Mb-Ram dedicates 24Mb. This fact cause why App doens't work on all devices. This is where i think problem is.

Comment #9

Posted on Jan 24, 2013 by Grumpy Hippo

Good to see that this issue is closed already.

When can we expect the latest JAR? Tentative Date ?

Or Shall we download and compile the latest code?

Comment #10

Posted on Mar 5, 2013 by Swift Hippo

Released with 3.0.0

Comment #11

Posted on Mar 5, 2013 by Swift Hippo

Releasing now.

Comment #12

Posted on Mar 6, 2013 by Swift Giraffe

Comment deleted

Comment #13

Posted on Mar 6, 2013 by Swift Giraffe

Comment deleted

Comment #14

Posted on Mar 6, 2013 by Swift Giraffe

Hi guys. I tested new release and it works fine with file, but.... seems there is a problem in text format (this problem occurs only if i use call() method to save response on file too). For example, if WS response is an Xml String, in which open and close tag are rappresented by special characters like "<" and ">" or "<" and ">", occurs an XmlPullParser Exception. If WS response is simple text like "GUID", there is no error but happen this:

Example with classical call() method -> httpTransport.call(soapAction, Envelope). Response dump is:

GUID

Example with new call() method (i set header's List to null) -> httpTransport.call(soapAction, Envelope, null, File). Response dump is:

GUID ������������������������

As you can see, something is written after Envelope node is closed. This "something", instead, seems that's not written in file.

Comment #15

Posted on Mar 6, 2013 by Swift Hippo

Can you file this as a separate new issue and maybe figure out what is going on and send a fix as pull request?

Comment #16

Posted on Mar 6, 2013 by Swift Giraffe

Problem is that i can't find source code. If i go here:

https://github.com/mosabua/ksoap2-android/tree/

i can't find java files. Directories seem empties

Comment #17

Posted on Mar 6, 2013 by Swift Hippo

What are you talking about .. its all there.. e.g. https://github.com/mosabua/ksoap2-android/blob/master/ksoap2-base/src/main/java/org/ksoap2/SoapEnvelope.java

Comment #18

Posted on Mar 6, 2013 by Swift Giraffe

Sorry, i didn't see it. Too work turned me stupid

Status: Fixed

Labels:
Type-Defect Priority-Medium