Guest User

Untitled

a guest
Oct 20th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Memory Snapshot Root Path</title>
  5. <style type="text/css">body { font-family: sans-serif; }</style>
  6. <script type="text/javascript">
  7. "use strict";
  8. window.onload = () => {
  9. let key;
  10.  
  11. const map = new WeakMap();
  12. const createButton = document.getElementById("createButton");
  13. const destroyButton = document.getElementById("destroyButton");
  14.  
  15. createButton.addEventListener("click", () => {
  16. key = new SomeKey();
  17. map.set(key, new Metadata());
  18. });
  19.  
  20. destroyButton.addEventListener("click", () => {
  21. key = undefined;
  22. });
  23.  
  24. };
  25.  
  26. class SomeKey {
  27. }
  28.  
  29. class Metadata {
  30. constructor() {
  31. this.large = new LargeObject();
  32. }
  33. }
  34.  
  35.  
  36. class LargeObject {
  37. constructor () {
  38. this.buffer = new Uint8Array(10 * 1024 * 1024);
  39. }
  40. }
  41. </script>
  42. </head>
  43. <body>
  44. <h1>Chrome Devtools Snapshot WeakMap Retain Path (Issue #773722)</h1>
  45. <p>
  46. Click Create button to create a LargeObject instance that is retained via a WeakMap key.
  47. </p>
  48. <p>
  49. Then open the Memory tab of the Dev Tools and take a Heap Snapshot.
  50. </p>
  51. <p>
  52. You will not be able to see the retaining path for this LargeObject and the distance will be "-" even though it is retained via user code and cannot be garbage collected.
  53. </p>
  54. <button id="createButton">Create</button>
  55. <button id="destroyButton">Destroy</button>
  56. </body>
  57. </html>
Add Comment
Please, Sign In to add comment