From: madelson <1269046+madelson@users.noreply.github.com> Date: Wed, 1 Feb 2023 16:53:17 +0000 (-0500) Subject: Remove ArgumentState "caching" that leaked memory deserialization. (#81473) X-Git-Tag: accepted/tizen/unified/riscv/20231226.055536~4295 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=047ea6a72ceb6a67bab0d3a46587975daeaecff6;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Remove ArgumentState "caching" that leaked memory deserialization. (#81473) * Remove ArgumentState "caching" that leaked memory deserialization. fix #80933 * Remove now-unused field --- diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ReadStack.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ReadStack.cs index 3724f20..0d6df0a 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ReadStack.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ReadStack.cs @@ -37,9 +37,6 @@ namespace System.Text.Json /// private int _continuationCount; - // State cache when deserializing objects with parameterized constructors. - private List? _ctorArgStateCache; - /// /// Bytes consumed in the current loop. /// @@ -202,8 +199,6 @@ namespace System.Text.Json Current = _stack[_count - 1]; } } - - SetConstructorArgumentState(); } /// @@ -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(); - - var newState = new ArgumentState(); - _ctorArgStateCache.Add(newState); - - (Current.CtorArgumentStateIndex, Current.CtorArgumentState) = (_ctorArgStateCache.Count, newState); - } - else - { - Current.CtorArgumentState = _ctorArgStateCache![Current.CtorArgumentStateIndex - 1]; - } + Current.CtorArgumentState ??= new(); } } diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ReadStackFrame.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ReadStackFrame.cs index b35eb15..f099079 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ReadStackFrame.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ReadStackFrame.cs @@ -62,7 +62,6 @@ namespace System.Text.Json public List? PropertyRefCache; // Holds relevant state when deserializing objects with parameterized constructors. - public int CtorArgumentStateIndex; public ArgumentState? CtorArgumentState; // Whether to use custom number handling.