Last active
March 8, 2019 23:38
-
-
Save mhofman/5b6fe56abe6ee05145b49ec13dd257d6 to your computer and use it in GitHub Desktop.
WeakRef basic demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let target = {}; | |
let wr = new WeakRef(target); | |
let fg = new FinalizationGroup((iter) => { | |
for(const i of iter) { | |
log(i); | |
} | |
}); | |
fg.register(target, "hello world"); | |
target = null; | |
setTimeout(gc, 0); | |
log('If everything goes well, the garbage collector should be greeting you soon!'); | |
function log(msg) { | |
console.log(msg); | |
htmlConsole.log(msg); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>WeakRef Demo</title> | |
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1"> | |
<script src="https://bl.ocks.org/mhofman/raw/fe170f9492196e9eb09907c84ea28999/html-console.js"></script> | |
<script src="./demo-weak-ref.js"></script> | |
</head> | |
<body> | |
<div>Make sure to run chrome with <pre>--js-flags="--expose-gc --harmony-weak-refs"</pre></div> | |
<div>Valid as of Chrome 74.0.3721.1</div> | |
<div id="console"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment