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

Blob URL leak #55

Closed
fuerte656 opened this issue Jun 7, 2016 · 6 comments
Closed

Blob URL leak #55

fuerte656 opened this issue Jun 7, 2016 · 6 comments
Labels

Comments

@fuerte656
Copy link

We have encountered a problem with Pica when processing large amounts of images (i.e. 1000+). When we resize multiple images through Pica, eventually it stops working, and when we look into the Network tab of the Developer Tools (on Chrome), we can see a corrupted Blob URL (empty).

I have taken a look at the Pica's source code and found that Pica creates Blob URLs using the URL.createObjectUrl to pass them to the worker constructor. There is a code like this:

    return new Worker(URL.createObjectURL(
        new Blob([src], { type: 'text/javascript' })
    ));

The documentation for URL.createObjectURL says that you have to release these URLs when they are no longer needed using the URL.revokeObjectURL:

https://developer.mozilla.org/en/docs/Web/API/URL/createObjectURL

However, in the code above, the created Blob URL is not released and apparently gets orphaned. As a result, when too many Blob URLs are created, the URL.createObjectURL starts failing (perhaps, it reaches some browser's limit for a number of Blob URLs).

I was going to patch Pica to save a reference to the Blob URL and revoke it when the worker is terminated, but I have updated to 2.0.2 and found out that the resizeBuffer method does not use workers anymore. So this update works for me, but you may want to fix it for the resizeCanvas method.

@puzrin
Copy link
Member

puzrin commented Jun 7, 2016

https://github.com/substack/webworkify/blob/v1.2.1/index.js#L66

Seems browserified version was assembled with old version of webforkify.

@puzrin puzrin added the bug label Jun 7, 2016
puzrin pushed a commit that referenced this issue Jun 7, 2016
@puzrin
Copy link
Member

puzrin commented Jun 7, 2016

Fixed in 2.0.3, thanks for report!

@puzrin puzrin closed this as completed Jun 7, 2016
@puzrin
Copy link
Member

puzrin commented Jun 7, 2016

@fuerte656 BTW, could you explain your use case for resizeBuffer? I tended to deprecate it but left for compatibility with minimal features.

@fuerte656
Copy link
Author

fuerte656 commented Jun 9, 2016

I use Pica since version 1.0.7
And has researched source code, and found out that resizeCanvasis just wrapping around resizeBuffer. Then I have implemented splitting canvas to tiles and running it multi-thread.
At this moment, I have this code working with resizeBuffer.

@puzrin
Copy link
Member

puzrin commented Jun 9, 2016

Thanks for info.

@puzrin
Copy link
Member

puzrin commented Jun 24, 2016

browserify/webworkify#26 seems changes were rolled back due IE Edge bug. Anyway, webworers are cached for several seconds, and intensive use will not create a bulk of leaked objects.

I think, problem will be self-resolved in future

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

No branches or pull requests

2 participants