locked
Can JObject lead to Memory Leaks in High Usage Envrionment? RRS feed

  • Question

  • User1355836186 posted

    I am trying to implement solution in asp.net core 3. I need to make few private properties REDACTED for security purposes while logging into file. As JsonDocument is readonly and I cannot use JsonPath as well, I have shifted to NewtonSoft for this purpose and use JObject.Parse. My concerns are:

    • How much it will affect my performance?

    • Will it lead to memory leaks?

    Code:

    var requestTokens = JObject.Parse(requestBodyText); // parse request/response 
    
    foreach (string property in RedactedFields) //for each redacted field in list
    {
        JToken token = requestTokens.SelectToken(property); // apply jsonpath
        if (token != null) 
        {
            // jsonpath found
            ((Newtonsoft.Json.Linq.JValue)token).Value = "******REDACTED******";
            requestTokens.SelectToken(property).Replace(token);
        }
    }
    Tuesday, April 21, 2020 9:54 AM

All replies