Memory Management in Opencv.js

asked 2019-12-09 15:14:19 -0600

I'm using opencv.js in a static web page, no back end. Unfortunately, I keep crashing due to memory running out. It looks like opencv.js is the culprit and I was hoping someone might know if there is a way to prevent opencv memory leaks in the javascript version. I already call _mat_.delete() on every matrix when I'm done with it and clear out the canvas I'm displaying on when I'm done, but after several runs (6-8) I still run out of memory. What I'd like to know is if there is anything I'm missing or if opencv.js is just to heavy in development at the moment to be reliable for my use case?

edit retag flag offensive close merge delete

Comments

I've been able to resolve running out of memory by...

  1. Limit the resolution of any source image/video. Do this before read or long-running functions. Do this with css or utils' qvga, or resize(). I found CNN's may expect to operate on thumbnail-size images... it may even improve their consistency and output.
  2. Loops affecting image pixels could analyze ROI or every 3rd pixel (instead of entire mat).
  3. Use async/await. It resolves race conditions. You can update GUI/DOM with a small timeout during process.
  4. Try an AIMD approach, as is used to monitor and resolve a network's data reliably.
  5. Are you sure the mat was deleted, and that was best in terms of performance? Use try/catch and log errorMessage to your advantage.
  6. Is it device or browser related?
kpachinger gravatar imagekpachinger ( 2020-04-16 06:40:31 -0600 )edit