zxing-js / library

Multi-format 1D/2D barcode image processing library, usable in JavaScript ecosystem.
https://zxing-js.github.io/library/
Apache License 2.0
2.49k stars 548 forks source link

Memory leak when continuously decoding for long time #391

Open urkku opened 3 years ago

urkku commented 3 years ago

Describe the bug It seems like there is a memory leak when decoding QR code continuously. Memory footprint seems to be increasing around 30mb/15min and in 1 hour memory footprint has increased by at least 120mb. It seems to be tied to decoding speed, since reducing the decoding speed will slow down the memory leak. On pc it will rise until it hits some max cap, but on mobile it will crash when max memory is reached. Since my application should be scanning 24/7 it will crash eventually depending on timebetweenscans.

To Reproduce Steps to reproduce the behavior:

  1. Go to https://zxing-js.github.io/library/examples/qr-camera/
  2. Select decode continuously
  3. Hit start and check the starting memory footprint for the tab from chrome task manager
  4. Keep tab active and let the camera decode run for 15min - 1 hour
  5. check the memory footprint again.

Expected behavior When majorGc hits all memory is freed and memory does not keep increasing indefinitely

Screenshots memincrease This is after active for sometime.

Desktop: Browser Chrome, firefox

Smartphone (That tested crashes):

Additional context Since this seems to be related to amount of decode tries, i was thinking about the decodeContinuously() loop() but my knowledge ran out and cant really solve what is happening that is causing the memory to increase that is leading to crash.

benjamincreativedk commented 3 years ago

Could it be the console logging millions of tries in short time (the NotFoundException).

odahcam commented 3 years ago

Yes, it could also be a problem due to the recursive decode loop, but most probably because of the big number of exceptions.

NoahGaeta commented 3 years ago

Bump, experiencing the same issue and the logging doesn’t seem to be the root cause. I programmatically remove all logs before building.

rvalitov commented 2 years ago

Tested the example link with on PC with Chrome 107.0.5304.88 for 2 hours. Memory consumption 50-100Mb, changes back and forth.