Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
474 views
in Technique[技术] by (71.8m points)

c# - Newtonsoft.JSON is taking way too much memory with large JSONs

I'm using Newtonsoft.Json to parse Jsons of about 100MB in size. I'm deserializing them into dynamic objects to work with them later. I was expecting the app to not use much more than the 100MB of ram, however this it not the case at all. I made a debug application to test the memory usage and to my surprise, it is at 435MB after deserializing.

I'm using a memory effcient code with disposing and streams:

            dynamic json;
            using (StreamReader sr = new StreamReader("C://Users/Brigan/JSON.json"))
            using (JsonReader reader = new JsonTextReader(sr))
            {
                JsonSerializer serializer = new JsonSerializer();

                 json = serializer.Deserialize<dynamic>(reader);
            }

This is all the application does. The code was taken and changed for reading a file from the official suggestions at https://www.newtonsoft.com/json/help/html/Performance.htm#MemoryUsage.

Looking at the memory profile: Object type : Amount : Size in bytes : Total size in bytes

question from:https://stackoverflow.com/questions/65899953/newtonsoft-json-is-taking-way-too-much-memory-with-large-jsons

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...