Very large SOAP response - Android- out of memory error

前端 未结 3 626
無奈伤痛
無奈伤痛 2020-11-28 11:53

I have an application where i need to download a large amount of data via a SOAP call to a webservice into the application when it is first run. The response is then sent to

3条回答
  •  温柔的废话
    2020-11-28 12:05

    Two strategies to help you solve this problem:

    1. Save your SOAP XML stream directly to disk as you download it. Don't store it in memory.
    2. Parse it using a SAX-style parser, where you don't load the whole DOM in memory, but rather parse it in chunks.

    Depending on the kind of XML you are handling, using SAX parsers is usually harder in code; you will have to keep track of many things yourself, and you won't be able to "jump" from section to section of your DOM tree. But the memory consumption will be way lower.

    Take note, however, that many "high-level" network communication libraries usually load the whole XML DOM in memory, which might be the case here. You will probably have to create and manage the HTTP connection yourself, and then manually parse the result.

提交回复
热议问题