Getting an OutOfMemoryException while serialising to JSON?(序列化为 JSON 时出现 OutOfMemoryException?)
问题描述
我正在序列化,一个MultiDictionary<String,Object>
http://powercollections.codeplex.com/到 json .
它有 618 个元素,元素被深度嵌套,即单个对象中可能有几个类似字典的对象.我正在使用 JSON.Net
It has 618 elements with elements being deeply nested ,i.e. a single Object may have several dictionary like objects in it . I am using JSON.Net
String json = JsonConvert.SerializeObject(json, Newtonsoft.Json.Formatting.Indented);
我错过了什么?
更多信息:-这在我使用动态之前工作正常,我不得不切换到 MultiDictionary 以允许多个同名属性.它适用于大多数情况,只有当项目数量很大时才会中断.
MORE INFO: - This was working fine till i was using dynamic , i had to switch to MultiDictionary to allow multiple properties of the same name . It works for most cases , only when the number of items is large , it breaks .
更新:-
我已经能够控制内存消耗,但减少了一些递归添加到每个元素的元素.
I have been able to get a hold of the Memory consumption but cutting down on some elements that were getting added recursively to each element.
推荐答案
您似乎遇到了 Ciruclar Reference 导致 OutOfMemoryException 或您的对象对您的内存来说太大了.使用 NDepend 进行检查.
It appears that you're running into Ciruclar Reference that is causing OutOfMemoryException or your objects are simply too large for your memory. Use NDepend to check this.
您可能会发现获取对象的总大小很有用一个>.
这篇关于序列化为 JSON 时出现 OutOfMemoryException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:序列化为 JSON 时出现 OutOfMemoryException?
基础教程推荐
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- WPF 模态进度窗口 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
