pa7 / nude.js

Nudity detection with JavaScript and HTMLCanvas

Home Page:http://www.patrick-wied.at/static/nudejs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Web workers never terminated

joshi1983 opened this issue · comments

A new web worker is made every time scan is called but the old workers are never closed or terminated.

We probably want to call terminate as documented here:
https://developer.mozilla.org/en-US/docs/Web/API/Worker/terminate

The following screenshot is from Google Chrome Developer Tools "Source" tab after scanning multiple images with nude.js:
image

Related to #1

I added myWorker.terminate() to the onmessage callback to fix the problem for me:
``

   scanImage = function(){
		// get the image data
		var image = ctx.getImageData(0, 0, canvas.width, canvas.height),
		imageData = image.data;

		var myWorker = new Worker('/lib/nudejs/worker.nude.js'),
		message = [imageData, canvas.width, canvas.height];
		myWorker.postMessage(message);
		myWorker.onmessage = function(event){
			resultHandler(event.data);
			myWorker.terminate();
		}
	},

Sorry but I don't have time to clone the repository and create a pull request.