Skip to content

Instantly share code, notes, and snippets.

@jussi-kalliokoski
Created February 25, 2013 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jussi-kalliokoski/5033123 to your computer and use it in GitHub Desktop.
Save jussi-kalliokoski/5033123 to your computer and use it in GitHub Desktop.
A polyfill for ArrayBuffer#dispose
void function () {
if ( 'dispose' in ArrayBuffer.prototype ) return
var blob = new Blob([''], {
type: 'text/javascript'
})
var url = URL.createObjectURL(blob)
var worker = new Worker(url)
URL.revokeObjectURL(url)
Object.defineProperty(ArrayBuffer.prototype, 'dispose', {
writable: true,
enumerable: false,
value: function () {
worker.postMessage(this, [this])
}
})
}()
var x = new Float32Array(16)
console.log(x.length) // 16
x.buffer.dispose()
console.log(x.length) // 0
@jussi-kalliokoski
Copy link
Author

@RetroModular:

Hi!

Nice to hear that it actually does something useful! I'm now quite convinced that something like this shouldn't be standardized, but... Uinfortunately until the garbage collectors become smarter, we need to make our applications smarter to deliver the best performance. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment