Created
May 24, 2023 06:18
-
-
Save cometkim/96bb3bdc642b435cc2ab230f99350f80 to your computer and use it in GitHub Desktop.
Is growable SAB GC-able?
This file contains hidden or 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> | |
<head> | |
<meta charset="utf-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1" /> | |
<title>SharedArrayBuffer GC test</title> | |
</head> | |
<body> | |
<div id="root"></div> | |
<script type="module"> | |
let registry = new FinalizationRegistry(v => { | |
console.log('Just finalized ', v); | |
}); | |
let sab = new SharedArrayBuffer(4 * 1024 * 1024); | |
let growableSab = new SharedArrayBuffer(0, { maxByteLength: 4 * 1024 * 1024 }); | |
registry.register(sab, "sab"); | |
registry.register(growableSab, "growable sab"); | |
let worker = new Worker('worker.js', { type: 'module' }); | |
worker.postMessage({ sab }); | |
worker.postMessage({ sab: growableSab }); | |
(function() { | |
console.log("grow sab"); | |
growableSab.grow(4 * 1024 * 1024); | |
registry.register({}, "tmp"); | |
})(); | |
</script> | |
</body> | |
</html> |
This file contains hidden or 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
console.log('Hello from Worker!', location.origin); | |
self.addEventListener('message', e => { | |
test(e.data.sab); | |
}); | |
function test(sab) { | |
console.log('Initilized with ', { sab }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment