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

Memory leak while generating a lot of server side graphs #30

Closed
varsha2409 opened this issue Jul 20, 2017 · 6 comments · Fixed by #43
Closed

Memory leak while generating a lot of server side graphs #30

varsha2409 opened this issue Jul 20, 2017 · 6 comments · Fixed by #43

Comments

@varsha2409
Copy link

varsha2409 commented Jul 20, 2017

Hi,

I am generating a lot of images on server side. During the process, Node is consuming a lot of memory (~ 1.5 GB).
I am calling chartNode.destroy(), still memory is not getting released.

Does anyone knows, where else there could be a memory leak?

PFB my code:

	var ChartjsNode = require('chartjs-node');
	var chartNode = new ChartjsNode(335, 250);

	return chartNode.drawChart(chartJsOptions)
		.then(() => {
			return chartNode.getImageDataUrl('image/jpeg')
		})
		// chart is created		
		// write to a file
		.then(() => {
			return chartNode.writeImageToFile('image/jpeg', 'temp/testimage' + GLOBAL_CHART_COUNT + '.jpeg')
		})
		.then((out_img) => {
			console.log(out_img)
			// chart is now written to the file path
			chartNode.destroy();
			chartJsOptions = null;
		});
@varsha2409 varsha2409 changed the title chartNode.destroy() is not working Memory leak while generating a lot of server side graphs Jul 20, 2017
@sedouard
Copy link
Contributor

Hey @varsha2409 I would check to see if something is holding on to the chartNode reference.

Often times when you see these kinds of issues it is due to a large object (like chartNode which contains a virtual DOM) that sits high in scope and never gets dereferenced for garbage collection.

@varsha2409
Copy link
Author

Hey @sedouard did you find anything?
I analysed the heap dump, there are many ChartElement, Chart.Controller and other Chart related objects.
I even did a force GC after every chart is created, these elements were still present.

@sedouard
Copy link
Contributor

@varsha2409 are you able to copy/paste the full context you're running this library in? I'm interested in seeing how it is repeatedly called. I suspect you are holding on to a references and thats why you're experiencing a leak.

@moberemk
Copy link
Contributor

moberemk commented Jan 8, 2018

@varsha2409 I've got a PR open, #43, that may address your issues--any chance you could give my fork a go to see if it helps you at all?

piercus added a commit to piercus/videoplot that referenced this issue Apr 13, 2018
@tscritch
Copy link

tscritch commented Jun 1, 2018

Hey guys,

I'm still having trouble with this. Calling destroy is not removing the instance of the chartNode.

I am using v1.7.1

Any insight?

return new Promise(function (resolve, reject) {
  var chartNode = new Chart(_options.width, _options.height)

  var options = {...}

  chartNode.drawChart(options)
        .then(() => {
          if (_options.base64) {
            // if base64 was in the query then return base64 data
            return chartNode.getImageDataUrl(_options.type)
          } else {
            // else return the image buffer
            return chartNode.getImageBuffer(_options.type)
            }
        })
        .then(image => {
          resolve(image)
        })
        .finally(() => {
          chart.destroy()
        })
        .catch(error => {
          reject(error)
        })
    })

@jacktuck
Copy link

jacktuck commented Jun 5, 2018

@tscritch I think u want to be destroying the chart instance in ur finally block? chartNode.destroy ?

Skywalker-11 added a commit to Skywalker-11/openITCOCKPIT that referenced this issue Jan 21, 2020
When running openITCOCKPIT for a long time the nodejs server running ChartRenderer.js consumes more and more memory. This should fix it. See vmpowerio/chartjs-node#30
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

Successfully merging a pull request may close this issue.

5 participants