question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Preventing memory leak with detectAllFaces() ?

See original GitHub issue

I am using detectAllFaces() with TinyFaceDetector. Every 500ms I feed it a new image to analyze. I noticed that I’m getting a memory leak because new canvas elements keep getting created and are never disposed of (I can see them in the Developer Tools’ Canvas tab).

What is the proper way to dispose of all these temporary canvas ?

P.S. Thanks for a great library!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
justadudewhohackscommented, Jul 6, 2019

Hey Jean-Philippe 😃

As far as I can tell, each time detectAllFaces() is called with an HTMLImageElement as the first parameter, it creates a <canvas> element and stores it in an array. This is done in NetInput.js at line 35-36:

Yes, this is correct.

As far as I can tell, these canvases never get garbage collected.

They should get garbage collected, otherwise you will run out of memory pretty quickly. Maybe you can share some code of what you are doing? If these canvases do not get garbage collected, then there is probably some reference dangling around somewhere.

Maybe you are unintenendly storing the NetInputs on some global object? Maybe the Dev Tools you are using itself cause the memory leak, because it is holding references to the canvases for debugging purposes. Same goes for logging the objects to the console, which will prevent them from being garbage collected until you clear your console.

3reactions
Amrit9939commented, Aug 27, 2021

i have same issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Avoid memory leaks with promises and loop in coffee-script ...
The solution was to dispose the tensor copy sent to detectFaces. faceapi.detectAllFaces(_tensorFrame, @faceDetectionOptions).then ...
Read more >
How to Find, Fix, and Prevent Node.js Memory Leaks
Memory management for any application is essential. This post looks at what memory leaks are and how to avoid them in Node.js applications....
Read more >
Causes of Memory Leaks in JavaScript and How to Avoid Them
In this article, we will explore programming patterns that cause memory leaks in JavaScript and explain how to improve memory management.
Read more >
Understanding memory leaks in node.js part 1 - alxolr
Internals. In node.js the status of your memory can be tracked with the following command process.memoryUsage() which returns the following JSON:.
Read more >
Memory Leaks in JavaScript and how to avoid them. - Medium
hugeString is kept in memory until the app stops, although never used. function setCallback() { const data = { counter: 0, hugeString: new...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found