Skip to content

Commit 1be1a80

Browse files
author
Naoaki Yamada
committed
Fix browser memory leaks
1 parent d91a2f6 commit 1be1a80

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,15 @@ loader.pitch = function(request) {
176176
workerUrl = `"data:,importScripts('"+location.origin+${workerUrl}+"')"`;
177177
}
178178

179+
// workerUrl will be URL.revokeObjectURL() to avoid memory leaks on browsers
180+
// https://github.com/webpack-contrib/worker-loader/issues/208
181+
179182
return cb(null, `
180183
var addMethods = require(${loaderUtils.stringifyRequest(this, path.resolve(__dirname, 'rpc-wrapper.js'))})
181184
var methods = ${JSON.stringify(exports)}
182185
module.exports = function() {
183186
var w = new Worker(${workerUrl}, { name: ${JSON.stringify(filename)} })
187+
URL.revokeObjectURL(${workerUrl});
184188
addMethods(w, methods)
185189
${ options.ready ? 'w.ready = new Promise(function(r) { w.addEventListener("ready", function(){ r(w) }) })' : '' }
186190
return w

0 commit comments

Comments
 (0)