TonySerMor / ksoap2-android

Automatically exported from code.google.com/p/ksoap2-android
0 stars 0 forks source link

OutOfMemory if response is huge #137

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
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.

Original issue reported on code.google.com by giuseppe...@gmail.com on 3 Oct 2012 at 5:02

GoogleCodeExporter commented 8 years ago
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.

Original comment by mosa...@gmail.com on 10 Oct 2012 at 6:08

GoogleCodeExporter commented 8 years ago
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

Original comment by giuseppe...@gmail.com on 10 Oct 2012 at 8:00

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

Original comment by mosa...@gmail.com on 10 Oct 2012 at 2:47

GoogleCodeExporter commented 8 years ago
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).

Original comment by giuseppe...@gmail.com on 10 Oct 2012 at 2:53

GoogleCodeExporter commented 8 years ago
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 ;-) 

Original comment by mosa...@gmail.com on 10 Oct 2012 at 7:58

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

Original comment by mosa...@gmail.com on 12 Nov 2012 at 7:41

GoogleCodeExporter commented 8 years ago
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?

Original comment by anatoliy...@gmail.com on 13 Nov 2012 at 9:16

GoogleCodeExporter commented 8 years ago
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.

Original comment by giuseppe...@gmail.com on 13 Nov 2012 at 10:28

GoogleCodeExporter commented 8 years ago
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?

Original comment by Abba...@ivymobility.com on 24 Jan 2013 at 9:22

GoogleCodeExporter commented 8 years ago
Released with 3.0.0

Original comment by mosa...@gmail.com on 5 Mar 2013 at 7:11

GoogleCodeExporter commented 8 years ago
Releasing now.

Original comment by mosa...@gmail.com on 5 Mar 2013 at 7:50

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
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:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body><ValidateUserResponse xmlns="http://tempuri.org/">
<ValidateUserResult>GUID</ValidateUserResult>
</ValidateUserResponse>
</s:Body>
</s:Envelope>

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

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body><ValidateUserResponse xmlns="http://tempuri.org/">
<ValidateUserResult>GUID</ValidateUserResult>
</ValidateUserResponse>
</s:Body>
</s:Envelope>�����������������������
���

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

Original comment by giuseppe...@gmail.com on 6 Mar 2013 at 12:01

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

Original comment by mosa...@gmail.com on 6 Mar 2013 at 4:08

GoogleCodeExporter commented 8 years ago
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

Original comment by giuseppe...@gmail.com on 6 Mar 2013 at 4:21

GoogleCodeExporter commented 8 years ago
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

Original comment by mosa...@gmail.com on 6 Mar 2013 at 6:29

GoogleCodeExporter commented 8 years ago
Sorry, i didn't see it. Too work turned me stupid

Original comment by giuseppe...@gmail.com on 6 Mar 2013 at 6:43