Android中的SimpleXML内存不足错误 [英] SimpleXML OutOfMemory error in Android

查看:168
本文介绍了Android中的SimpleXML内存不足错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是简单的2.4.1库在我的Andr​​oid项目。我试图处理的700 KB(〜6K线)的XML文件时,此内存不足错误 - 在这里处理装置,读取该文件,做了一些计算,然后将结果写入到一个新文件。它工作得很好了600 KB的文件,至少我没有得到同样的错误呢。

I'm using Simple 2.4.1 library in my Android project. I got this OutOfMemory error when trying to process an XML file of 700 kB (~6k lines) - process here means read the file, do some calculations, and then write the result to a new file. It worked fine with a 600 kB file, at least I haven't got the same error yet.

下面是如何将XML如下:

Here's how the XML looks like:

<items>
    <item1 id="1">
        <subitem1 id="1">
            <subsubitem1 id="a">
                <iteminfo>
                    <info>blublub</info>
                    <info>blublub</info>
                </iteminfo>
            </subsubitem1>
            <subsubitem1 id="b">
                <iteminfo>
                    <info>blublub</info>
                    <info>blublub</info>
                </iteminfo>
            </subsubitem1>
        </subitem1>
    </item1>
</items>

有什么解决方法吗?

Is there any workaround to this?

推荐答案

这可能仅仅是拿在内存太多没有做一些与它的情况。如果你想想看,如果你正在读入文件到内存,700KB,你们在管理费用增加了XML解析的休息,你的应用程序和其他应用程序,这将需要一些内存和CPU时间在设备上,它归结到这不是一个好主意。

This may simply be a case of holding too much in memory without doing something with it. If you think about it, if you are reading a file into memory that is 700kb, and you add in overheads for the rest of the xml parsing, your application, and other applications that will want some memory and CPU time on the device, it boils down to this not being a good idea.

没有一个解决方法,因为这样,任何你觉得会不会是从编程感觉很好,因为你仍然试图保持XML的700KB内存中,当你也许并不需要多数认为。

There isn't a workaround as such, any that you find would not be very good from a programming sense, because you are still trying to hold 700kb of xml in memory, when you probably do not need most of that.

我建议你找,只要你能腾出资源去除存储这些数据的方法。你可以保存元素,你在提交一份有意义的方式,或通过数据库的东西和索引查找,这将允许你持有大量的数据,但不是抓着这一切在内存中,你可以看一下在数据库中数据你要明确,只有把,早在内存。这样,你限制你使用的资源,人谁下载你的应用程序不会得到可疑,当您使用了很多他们的记忆中。

I suggest that you find a way of removing this data from memory as soon as you can to free up resources. You could save the elements you find in a meaningful way to file or something and index via database, which would allow you to hold large amounts of data, but instead of holding onto it all in memory, you can look up in the database for the data you want specifically, and only bring that back in to memory. This way you limit your use of resources, and people who download you application won't get suspicious when you are using up a lot of their memory.

这篇关于Android中的SimpleXML内存不足错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆