- 0
Help with Javascript memory leak using Google Graphs
-
Recently Browsing 0 members
- No registered users viewing this page.
-
Similar Content
-
Everyone seems powerless against Oracle's ownership of the JavaScript trademark 1 2
By Usama Jawad96,
- oracle
- javascript
- (and 5 more)
- 29 replies
- 0 views
-
Microsoft engineer shows how bad code can lead to your Windows PC slowing down
By hellowalkman,
- microsoft
- windows 11
- (and 12 more)
- 19 replies
- 0 views
-
HTML, CSS, & JavaScript All-in-One For Dummies (worth $39.99) free download ends today
By News Staff,
- ebook offer
- sponsored
- (and 3 more)
- 0 replies
- 0 views
-
Download HTML, CSS, & JavaScript All-in-One For Dummies ($39.99 Value, now FREE)
By News Staff,
- ebook offer
- sponsored
- (and 5 more)
- 0 replies
- 0 views
-
PSA: Windows 11's BYPASSNRO is still part of Rufus as it receives its latest update
By hellowalkman,
- rufus
- windows 11
- (and 8 more)
- 4 replies
- 0 views
-
Question
Slugsie
I'm pretty new to Javascript, and I'm trying to write a web page that displays the utilisation of our servers. I have it all working fine, except for the fact that over time the page consumes more and more memory, until eventually the browser just gives up and displays an out of memory error. If I disable the code that displays the graphs (it still collates the data, just doesn't display the resultant graphs) then memory usage stays pretty flat and well under control (typically under 25,000K - all memory stats taken from Chromes Task Manager). Add the graphs back in and it starts around 40,000K, but grows and grows. I've seen it reach nearly 1GB after many hours. The page is intended as a dashboard display, running all the time on a Smart TV, with the figures updated every minute.
Here is the code that draws the graphs:
function drawAChart(dataSource, chartHead, elementDIV){ // // Take the data, and draw the actual graph dataSource.unshift(chartHead); var dataS = new google.visualization.arrayToDataTable(dataSource); var chartS = new google.visualization.ColumnChart(document.getElementById(elementDIV)); chartS.draw(dataS, options); // Try and clean up to help the GC dataS = undefined; chartS = undefined; dataSource = undefined; }
When I comment out the lines relating to chartS then the memory usage stays low.
dataSource is an array, typically in the form [['Server name',<%age number 0-100>,<colour>], ...]
chartHead is typically ['Server','Useage', {role: 'style'}]
elementDIV is just the name of the DIV that the graph is displayed in.
The chart options are:
var options = { height: 130, legend: { position: 'none' }, chartArea: { left: 50, top: 10, width: '95%', height: '75%' }, vAxis: { viewWindow: { min: 0, max: 100 }, ticks: [{v:0, f:"0%"}, {v:25, f:"25%"}, {v:50, f:"50%"}, {v:75, f:"75%"}, {v:100, f:"100%"}] }, bar: { groupWidth: '95%' } };
I am using Google's charting routines from
which are initialised with:
google.charts.load('currentpackages: ['corechart']}); google.charts.setOnLoadCallback(doProcess);
I know I'm missing something, probably obvious to any seasoned Javascript devs, but I just can't figure it out. Hopefully I've given enough info for someone to point me in the right direction.
Link to comment
https://www.neowin.net/forum/topic/1320768-help-with-javascript-memory-leak-using-google-graphs/Share on other sites
0 answers to this question
Recommended Posts