使用 Web 服务的 SQL CE OutOfMemoryException [英] SQL CE OutOfMemoryException consuming web service

查看:27
本文介绍了使用 Web 服务的 SQL CE OutOfMemoryException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试通过网络服务下载文档时,我们不断收到 OutOfMemory 异常.我们将文档字节数组数据存储为序列化消息对象的一部分,原始文档的大小都约为 500kb.消息对象图中唯一的另一件事是用于关联的两个字符串属性.

We are continually receiving OutOfMemory exceptions when trying to download documents via a web service. We are storing the documents byte array data as part of a serialized mesage object and the original documents are all ~500kb in size. The only other thing in the message's object graph are two string properties for correlation.

我们曾尝试检索压缩和未压缩的文档,但遇到相同的问题.现在我相信异常是在尝试反序列化消息而不是下载流时引发的.

We have tried retrieving the document compressed and uncompressed with the same issues. Now I believe that the exception is been raised when trying to deserialize the message and not while downloading the stream.

我知道这是一个含糊不清的问题,但是你们中的任何人知道是什么导致了这种情况吗?这里传输的数据量似乎非常小,传输时设备上几乎没有发生其他事情.

I know this is a vague question, but do any of you have any idea what could be causing this? The amount of data transferred here seems very small and there is little else happening on the device at the time of transfer.

推荐答案

Windows Mobile 设备上的内存非常紧张 -- 使用它确实是一个痛苦的世界.首先,一个进程的总内存是(如果我没记错的话)32 MB.现在不仅被代码内存分配填满,还被从 DLL、EXE 等加载的代码填满.

Memory is VERY tight on Windows Mobile devices -- it really is a world of pain to work with. First of all, your total memory for a process is (if I remember right) 32 MB. Now that gets filled up not just with in-code memory allocations, but also loaded code from DLLs, the EXE and such.

现在,当您将 500KB 下载到字节数组中时,它不仅需要 500KB.它需要 500KB 的 CONTIGUOUS MEMORY,一旦应用运行了一小段时间,它就不太可能找到.

Now when you're downloading the 500KB into a byte array, it doesn't just need 500KB. It needs 500KB of CONTIGUOUS MEMORY, something it's very unlikely to find once the app has been running for a short while.

我的建议是直接使用 HttpRequest 而不是 Web 服务下载文件.也许 Web 服务可以传回您需要的 URL 或类似的东西.但是直接下载文件,你可以分块处理——读取 8K,然后将该 8K 写入磁盘,然后读取另一个 8K,等等.

My recommendation would be to download the files directly with an HttpRequest rather than the web service. Maybe the web service can pass back the URL that you need or something like that. But download the file directly and you can process it in chunks -- read 8K, then write that 8K to disk, then read another 8K, etc.

这篇关于使用 Web 服务的 SQL CE OutOfMemoryException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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