Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web workers never terminated #24

Open
joshi1983 opened this issue Feb 14, 2020 · 1 comment
Open

Web workers never terminated #24

joshi1983 opened this issue Feb 14, 2020 · 1 comment

Comments

@joshi1983
Copy link

joshi1983 commented Feb 14, 2020

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

@joshi1983
Copy link
Author

joshi1983 commented Feb 14, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant