I have 175MB json file, and I am loading this file data into a static JObject variable to use for a query. However, while running console application, I could see that this process occupy 2.5GB memory.
Here is my code snippet:
public class LocationData
{
public static JObject LOCATION { get; set; }
public static void FillData()
{
JArray jArray = new JArray();
using (StreamReader file = File.OpenText("somefiles.json"))
using (JsonTextReader reader = new JsonTextReader(file))
{
jArray.Add(JObject.ReadFrom(reader));
}
LocationData.LOCATION = new JObject(new JProperty("Location", jArray));
jArray = null;
}
}
I fill LOCATION once thereafter here is my GetData code for querying data from LOCATION:
LocationData.LOCATION.SelectTokens(tokenString).ToList();
I wanted a solution around this to handle such data and keep data in memory (Since I wanted to use this data frequently) with adequate memory utilization. I request your help on best practices to follow here to manage such data in a C# application. Do let me know in case if you need more info to answer this.
Thanks in advance.