Html2canvas: Calling html2canvas multiple times increases memory usage on Chrome

Created on 28 Jul 2018  Â·  11Comments  Â·  Source: niklasvh/html2canvas

Bug reports:

Calling html2canvas multiple times increases memory usage.

Specifications:

  • html2canvas version tested with: html2canvas 1.0.0-alpha.12
  • Browser & version: Chrome 68.0.3440.75
  • Operating system: Mac OS 10.13.6 (17G65)

How to reproduce

  1. Go to https://html2canvas.hertzen.com/
  2. Open the developer tools performance monitor: 717 DOM Nodes, JS heap size 14.8 MB
  3. Press 'Try it out'
  4. Press 'Capture' and close the image
  5. Repeat this several times
  6. Open the developer tools performance monitor: 3578 DOM Nodes, JS heap size 19.3 MB

It appears the clean up of the cloned nodes is not working as expected, or Chrome isn't cleaning it up.

chrome

Most helpful comment

This bug still happen in the last version (1.0.0-rc5). Please fixed this.

All 11 comments

me too, wait fix...

I use vue-cli3, calling html2canvas multiple times increases memory usage, and fail to compile my project.
Otherwise, some picture in my page can't display, calling several times but no out of usage.

I am having the same problem. The nodes are all detached but aren't being garbage collected.

Hello! I made some memory profiling using chrome and found a bottleneck with one closure, in my case I commented out the code snippet which isn't used in our case, so this solves the issue for us.

SourceCodeScreenshot

Thanks for the suggestion @ThunderWorm, but unfortunately this did not fix the problem for me.

We fixed our memory leak by making a change in the file Clone.js around line 541.
The previous code was:
image
It seems that this kept a reference to documentClone so it was never deleted. Instead we made the function async to wait for the response from iframeLoader.
The code looks like this:
image

This seems to be fixed in the last version (1.0.0-rc3).
However, in this version, logging cannot be disabled due to a bug.

This bug still happen in the last version (1.0.0-rc5). Please fixed this.

Any good news here? I got the problem too.

I'm also very troubled about this bug...
I use last version (1.0.0-rc.5).
I called canvas.remove() after called html2canvas but heap memory remained.
Do you have any idea to delete heap memory by html2canvas?

スクリーンショット 2020-05-31 01 22 56

I recommend this one: https://github.com/bubkoo/html-to-image. It is very easy to use. The multiple screenshot function can be realized without memory leak.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stevencherry1 picture stevencherry1  Â·  3Comments

Josh10101010 picture Josh10101010  Â·  3Comments

koreanman picture koreanman  Â·  4Comments

tjchambers32 picture tjchambers32  Â·  3Comments

wbarrantes picture wbarrantes  Â·  3Comments