Browse Source

Disable object identity tracking by default under interop (#1466)

Marko Lahma 2 years ago
parent
commit
24db194fae
2 changed files with 7 additions and 9 deletions
  1. 2 2
      Jint.Tests/Runtime/WeakSetMapTests.cs
  2. 5 7
      Jint/Options.cs

+ 2 - 2
Jint.Tests/Runtime/WeakSetMapTests.cs

@@ -63,7 +63,7 @@ public class WeakSetMapTests
     [Fact]
     [Fact]
     public void WeakSetWithInteropObject()
     public void WeakSetWithInteropObject()
     {
     {
-        var engine = new Engine();
+        var engine = new Engine(options => options.Interop.TrackObjectWrapperIdentity = true);
 
 
         engine.SetValue("context", new { Item = new Item { Value = "Test" } });
         engine.SetValue("context", new { Item = new Item { Value = "Test" } });
 
 
@@ -89,7 +89,7 @@ public class WeakSetMapTests
         parent.Child = child;
         parent.Child = child;
         child.Parent = parent;
         child.Parent = parent;
 
 
-        var engine = new Engine();
+        var engine = new Engine(options => options.Interop.TrackObjectWrapperIdentity = true);
 
 
         engine.SetValue("context", new { Parent = parent });
         engine.SetValue("context", new { Parent = parent });
 
 

+ 5 - 7
Jint/Options.cs

@@ -251,20 +251,18 @@ namespace Jint
         public List<IObjectConverter> ObjectConverters { get; } = new();
         public List<IObjectConverter> ObjectConverters { get; } = new();
 
 
         /// <summary>
         /// <summary>
-        /// Whether identity map is persisted for object wrappers in order to maintain object identity.
-        /// Defaults to true.
+        /// Whether identity map is persisted for object wrappers in order to maintain object identity. This can cause
+        /// memory usage to grow when targeting large set and freeing of memory can be delayed due to ConditionalWeakTable semantics.
+        /// Defaults to false.
         /// </summary>
         /// </summary>
-        public bool TrackObjectWrapperIdentity { get; set; } = true;
+        public bool TrackObjectWrapperIdentity { get; set; } = false;
 
 
         /// <summary>
         /// <summary>
         /// If no known type could be guessed, objects are by default wrapped as an
         /// If no known type could be guessed, objects are by default wrapped as an
         /// ObjectInstance using class ObjectWrapper. This function can be used to
         /// ObjectInstance using class ObjectWrapper. This function can be used to
         /// change the behavior.
         /// change the behavior.
         /// </summary>
         /// </summary>
-        public WrapObjectDelegate WrapObjectHandler { get; set; } = static (engine, target) =>
-        {
-            return new ObjectWrapper(engine, target);
-        };
+        public WrapObjectDelegate WrapObjectHandler { get; set; } = static (engine, target) => new ObjectWrapper(engine, target);
 
 
         /// <summary>
         /// <summary>
         ///
         ///