[英]HttpClient: limit response (downloaded file) size while using HttpResponseMessage.Content.ReadAsStreamAsync()
[英]Out of memory exception while deserializing response.Result.Content.ReadAsStreamAsync() for response more than 400 mb
如何反序列化为 2GB 左右的 object。
将 100000 条记录添加到 List 后退出 memory 异常。
请让我知道是否有替代方法可以在列表 object 或字符串中返回大约 900000 条记录?
var repsonse = httpClient.PostAsync(url,content);
List<object> lstObj = new List<object>();
using (var responseStream = response.Result.Content.ReadAsStreamAsync().Result)
{
using (var textReader = new StreamReader(responseStream))
{
using (var jsonReader = new JsonTextReader(textReader))
{
while (jsonReader.Read())
{
object o = serializer.Deserialize<object>(jsonReader);
lstObj.Add(o);
}
}
}
}
if you realy need to load 2gb of an object in memory, Go to the project properties, you need to select Target platform "AnyCpu", so you can run on 64bits and use the memory enter image description here
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.