Remove ArgumentState "caching" that leaked memory deserialization. (#81473)
authormadelson <1269046+madelson@users.noreply.github.com>
Wed, 1 Feb 2023 16:53:17 +0000 (11:53 -0500)
committerGitHub <noreply@github.com>
Wed, 1 Feb 2023 16:53:17 +0000 (16:53 +0000)
* Remove ArgumentState "caching" that leaked memory deserialization.

fix #80933

* Remove now-unused field

src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ReadStack.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ReadStackFrame.cs

index 3724f20..0d6df0a 100644 (file)
@@ -37,9 +37,6 @@ namespace System.Text.Json
         /// </summary>
         private int _continuationCount;
 
-        // State cache when deserializing objects with parameterized constructors.
-        private List<ArgumentState>? _ctorArgStateCache;
-
         /// <summary>
         /// Bytes consumed in the current loop.
         /// </summary>
@@ -202,8 +199,6 @@ namespace System.Text.Json
                     Current = _stack[_count - 1];
                 }
             }
-
-            SetConstructorArgumentState();
         }
 
         /// <summary>
@@ -393,20 +388,7 @@ namespace System.Text.Json
         {
             if (Current.JsonTypeInfo.Converter.ConstructorIsParameterized)
             {
-                // A zero index indicates a new stack frame.
-                if (Current.CtorArgumentStateIndex == 0)
-                {
-                    _ctorArgStateCache ??= new List<ArgumentState>();
-
-                    var newState = new ArgumentState();
-                    _ctorArgStateCache.Add(newState);
-
-                    (Current.CtorArgumentStateIndex, Current.CtorArgumentState) = (_ctorArgStateCache.Count, newState);
-                }
-                else
-                {
-                    Current.CtorArgumentState = _ctorArgStateCache![Current.CtorArgumentStateIndex - 1];
-                }
+                Current.CtorArgumentState ??= new();
             }
         }
 
index b35eb15..f099079 100644 (file)
@@ -62,7 +62,6 @@ namespace System.Text.Json
         public List<PropertyRef>? PropertyRefCache;
 
         // Holds relevant state when deserializing objects with parameterized constructors.
-        public int CtorArgumentStateIndex;
         public ArgumentState? CtorArgumentState;
 
         // Whether to use custom number handling.