Bug 140919 - WeakMap Object key expected to be garbage collected is not
Summary: WeakMap Object key expected to be garbage collected is not
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2015-01-26 19:21 PST by Joseph Pecoraro
Modified: 2015-01-27 14:23 PST (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph Pecoraro 2015-01-26 19:21:34 PST
* SUMMARY
In a LayoutTest I am adding to test WeakMap, an Object I expected to be garbage collected is not. This reproduces 100% for me in Debug (x84_64) builds, but does not in Release builds on the same machine.

* STEPS TO REPRODUCE
1. shell> run-webkit-tests --debug LayoutTests/inspector/model/remote-object-weak-collection.html
  => FAILURE

After these series of steps:

> strongKey1 = {id:1};
> strongKey2 = {id:2};
> weakMap = new WeakMap;
> 
> GCController.collect();
> weakMap.set(strongKey1, 1);
> weakMap.set(strongKey2, 2);
> GCController.collect();
> delete window.strongKey1;
> GCController.collect();
> weakMap.set({id:3}, 3);
> weakMap.set({id:4}, 4);
> GCController.collect();
> weakMap

I expect the temporary object {id:4} to be garbage collected, but it is not.

* RESULTS DIFF
--- Build/Debug/layout-test-results/inspector/model/remote-object-weak-collection-expected.txt
+++ Build/Debug/layout-test-results/inspector/model/remote-object-weak-collection-actual.txt
@@ -119,6 +119,31 @@
       "value": 2,
       "description": "2"
     }
+  },
+  {
+    "key": {
+      "type": "object",
+      "objectId": "<filtered>",
+      "className": "Object",
+      "description": "Object",
+      "preview": {
+        "type": "object",
+        "description": "Object",
+        "lossless": true,
+        "properties": [
+          {
+            "name": "id",
+            "type": "number",
+            "value": "4"
+          }
+        ]
+      }
+    },
+    "value": {
+      "type": "number",
+      "value": 4,
+      "description": "4"
+    }
   }
 ]
Comment 1 Joseph Pecoraro 2015-01-26 19:22:20 PST
Even though the test reproduces in Debug builds, I have seen some objects that I expect to get released, not get released in Release builds. I just do not have a reliable way to reproduce that issue.
Comment 2 Radar WebKit Bug Importer 2015-01-26 19:22:53 PST
<rdar://problem/19609705>
Comment 3 Joseph Pecoraro 2015-01-26 19:24:33 PST
The test and inspector pieces have not landed yet. It is currently up for review on bug 122867.
Comment 4 Joseph Pecoraro 2015-01-27 14:23:06 PST
Geoff and I debugged this for a bit, and it looks like this is okay. For one, eventually in the test the object does get cleaned up so long term that looks fine. But further investigation into why it was temporary alive, it looks like the object is alive because it is on the stack during collection. Adding a "timeout" between the map mutation and collection, the object goes away as expected!

Closing as behaves correctly.