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

2.0.0.beta 7 memory leak with nodejs #4388

Closed
albertyou2 opened this issue Oct 18, 2017 · 3 comments
Closed

2.0.0.beta 7 memory leak with nodejs #4388

albertyou2 opened this issue Oct 18, 2017 · 3 comments

Comments

@albertyou2
Copy link

OS: mac os 10.12.6 / centos 6.5 / ubuntu 16.04 ( i had tested under 3 OS)
node canvas : 1.6.7 ( now fabric.js only support 1.x.x)
fabric.js: v2.0.0-beta.7 (the latest version)

Hi @kangax

I found that there is a very bad memory leak issue ( maybe caused by node-canvas ,look at here : Automattic/node-canvas#1003 ) in fabric.js with nodejs.

Here is my test code :
...
{
let canvas = fabric.createCanvasForNode(800, 800);
canvas = null;
}
...
After called this code several times , memory usage grow from 78 MB to 1 GB.

i found a solution here : ( #1997 )
var canvas = fabric.createCanvasForNode();
// blah blah canvas manipulation
canvas.clear();
canvas.dispoose();
// garbage collection should be good now

BUT a new error came out:
TypeError: canvas.dispoose is not a function.

is there any solution in my case?Or fabric.js support node-canvas > 2.0.0.beta5 ?
Thank you very much .

@asturur
Copy link
Member

asturur commented Oct 18, 2017

dispoose is not a function. dispose is.
Can you try that?

You have to dispose a canvas since once you create a canvas other 2 gets created ( a cache one and a top layer one, and without disposing maybe they do not get cleared properly )

@albertyou2
Copy link
Author

@asturur
Thankyou very much for help!
I have tried "canvas.dispose();" It works fine in sync code like this:
var canvas = fabric.createCanvasForNode();
// blah blah canvas manipulation
canvas.clear();
canvas.dispose();

but i found that it does't work by calling in async code like this:
var canvas = fabric.createCanvasForNode();
canvas.loadFromJSON(jsonObj, () => {
canvas.renderAll();
....
canvas.dispose();
})

Am i missing sth??
Thank you again for helping!

@asturur
Copy link
Member

asturur commented Oct 19, 2017

mh.
are you keeping reference to the objects somewhere?
Each object as a canvas reference, if mantained alive will stop the GC from cleaning it away

How can you say is a leak and not resources taken from active stuff? what are you actually doing with the script?

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

No branches or pull requests

2 participants