issue with highcharts not properly releasing memory upon reload

A memory issue arises when attempting to reload a Highchart graph.

I have tried using chart.destroy() explicitly upon reloading and setting 'chart animation: false', but these solutions are not entirely effective in resolving the problem.

setInterval ( "initChart()", 1000*30 );`        

function initChart(){

    if ( typeof $ ( '#guage1' ).highcharts () !== 'undefined' )
    {
        $ ( '#guage1' ).highcharts ().destroy ();
    }

    var data = [{
        borderColor: "red",
        color: "#7cb5ec",
        innerRadius: "100%",
        radius: "100%",
        y: 60
    }];

    setHighcharts($('#guage1'), data);
    datas($('#guage1'),data);
}


function datas($container,data){

    var chart = $container.highcharts();

    if(typeof chart !== 'undefiend' || chart != null){

        var y = null;
        y = chart.series[0].data[0].y;

        for ( var i = y; i >= 0; i = i - (y / 80) )
        {
            chart.addSeries ( {
                data : [ {
                    y : i,
                    radius : '100%',
                    innerRadius : '100%',
                } ],
                stickyTracking : false,
                enableMouseTracking : false
            }, false )
        }
        chart.redraw ();

        Highcharts.each ( chart.series, function ( s )
        {
            s.update ( {
                borderColor : s.data[0].color
            }, false );
        } );
        chart.redraw ();
    }
    chart = null;
}


function setHighcharts($container, data1) {
console.log('');

    $container.highcharts ( {
        chart : {
            type : 'solidgauge',
            spacingBottom : 0,
            spacingTop : 0,
            spacingLeft : 0,
            spacingRight : 0,
            marginTop : 28,
            marginLeft : 28,
            marginRight : 28,
            marginBottom : 28,
            backgroundColor : 'rgba(255, 255, 255, 0.0)',
            style : {
                fontFamily : 'Nanum Gothic'
            },
            animation: false
        },

        title : {
            text : '',
            style : {
                display : 'none',
            }
        },

        pane : {
            startAngle : 0,
            endAngle : 360,
            background : [ { // Track for Move
                outerRadius : '112%',
                innerRadius : '88%',

                backgroundColor : 'rgba(17, 17, 26, 1)',
                borderWidth : 0
            } ]
        },

        yAxis : {
            min : 0,
            max : 100,
            lineWidth : 0,
            tickPositions : [],
            stops : [ [ 0, '#218ad8' ], [ 1, '#69ff05' ] // red
            ],
        },

        plotOptions : {
            solidgauge : {
                borderWidth : '15px',
                linecap : 'round',
                dataLabels : {
                    enabled : false
                },
                rounded: true
            }
        },
        series : [{
            data : data1,
        }]
    });
}

My page contains 5 gauge charts which reload every 30 seconds causing an increase in memory usage.

It seems that some object created is still retained in memory after each reload.

The memory size is 159.6MB on initial load and increases to 171.8MB after 7 reloads.

How can I properly free up memory upon each reload?

Answer №1

Avoid the practice of constantly destroying and reinitializing charts every 30 seconds, as it is not efficient. Instead, consider utilizing methods that allow for dynamic chart updates such as: chart.update(), series.addPoint(), series.setData() etc.

See a demo here:

For more information, refer to the API reference below:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unable to remove an element from my Array during verification

http://plnkr.co/edit/b1v87pUEykOJN4mKLFHa?p=preview My goal is to manage two arrays: one coming from an API called apiArray, and the other, toggleArray, will hold selected items from apiArray. The function selectBtn is meant to toggle items in and out of ...

When running `npm install`, it attempts to install version 1.20.0 of grpc even though version 1.24.2 is specified in

After running npm install on my React-Native project, an error occurred stating that it was attempting to install gRPC version 1.20.0, but my package.json and package-lock.json specified gRPC version 1.24.1. I attempted to fix the issue by adjusting the v ...

How is it possible that the Mongoose query is returning the correct result but I am unable to access its properties as expected?

Can $elemMatch be used to verify if the requested article page belongs to an authenticated user using passportjs req.isAuthenticated()? I'm encountering an issue where logging user._id gives me undefined, although req.user shows the correct user store ...

When trying to pull a component from Svelte, I receive an error message stating "Selection Range

I'm still relatively new to svelte, so I might be handling things incorrectly. Whenever I attempt to separate my button component, regardless of whether I name the component ./Button.svelte, ./Button, Button.svelte, or try variations with capitalizat ...

Is there a way for users to share their thoughts in response to the posts of

I'm looking to implement a feature that allows users to add comments on posts with an "add comment" button similar to what you see in platforms like Facebook. When the button is clicked, a small input box should open up and display the comment below t ...

dependencies in NodeJS packages

After defining an NPM package with specific dependencies, I proceed to create a new project folder. This folder contains a 'node_modules' directory at the root as well as a 'package.json' file. Next, I execute the command 'npm inst ...

Adjusting the position of an image on a webpage as the user scrolls

Looking to add some flair to your website by making an image slide to a specific spot when you scroll? Imagine the page loading with the image sliding elegantly to the left, then as you start scrolling, it smoothly transitions to the center or bottom of th ...

How to retrieve document.getElementsByName from a separate webpage using PHP and javascript

Hey there, I've been searching for a solution to this issue but haven't had any luck so far. I'm attempting to retrieve the value of the name test from an external website. <input type="hidden" name="test" value="ThisIsAValue" /> Up ...

Interactive JavaScript function designed to react to user commands

Struggling to develop a JavaScript/AngularJS function that notifies the user whether a entered number is too high or low (> 100 indicates it's too high)? Check out the HTML code below: <div> <p id="num">Number : <input type="nu ...

Executing [HTTPPost] request using JavaScript with ASP.NET

I have a controller method that fetches data from an API which I need to be able to call from two different places. The first location is the view (which is currently working), and the second is a JavaScript function. Here is the beginning of the controll ...

Unable to retrieve the iframe variable from the parent as it returns undefined

I am trying to retrieve a variable within an iframe from the parent index.html. Here is the index.html code: <!doctype html> <html lang="en-us> <head> <title>Test</title> </head> <body> <p>Test& ...

"Enhance your visuals with a rotating light source in combination with a camera and Orbit

In my Three.js scene, I've integrated OrbitControls.js for rotation and panning functionality. However, I'm facing an issue with the lighting setup - I want the lighting to move along with the camera, ensuring that the object is always well-illum ...

Guide on sending a PUT request using express.js

Currently delving into node.js and have a query regarding PUT requests I'm able to create an object and see it in the URL. However, I'm unsure of how to write a request to edit it - such as changing the price of a vehicle. Any guidance on writin ...

The content in ACF appears to be missing when displayed in the fancybox

I have configured ACF to appear in a fancybox. The fields are being pulled in (as I can see the hardcoded header information), but nothing from the ACF appears. I have linked it to call an ID, which is then associated with the section that should be displa ...

Retrieve the value attribute of the <li> element

For a school project, I am working on a small website where I need to iterate over an array populated by an SQL query. The data will be displayed in the following format: <ul class="list-group"> <li class="list-group-item" name="id" value="36 ...

Reviewing a document within an npm module

Recently, I developed an npm package called test_package_cat that is designed to access a json file (info.json) at the beginning of its execution. This involves having both index.js (the main entry point) and info.json situated at the same level. When I e ...

The changes in the dependency are not being updated in App Engine

Recently, I made a minor adjustment to one of the dependencies in my project. Surprisingly, it works flawlessly when tested locally. However, when deployed on the app engine, an error arises because the changes in the dependency are not being updated. Is ...

What is the best way to include a JavaScript function within a JSON file?

I am attempting to transform a JSON file into an object within my application, complete with embedded functions. However, I am facing difficulties in accomplishing this task. The JSON file causing issues is as follows: { "draw": function() { ctx.cle ...

Customizing Background Color in React Bootstrap Table Based on Value

Having a little issue that's causing me some trouble. I have a React Bootstrap Table displaying data from an API, and I'm looking to enhance it by changing the row color to green if a specific value is greater than zero. Here is an example: const ...

The challenge in displaying data from the backend using ajax in Vue.js 2.0 is hindering its visibility on the view

Currently, I am utilizing vue.js version 2.0, and the demo provided below is fully functional. <div class="container" id="app"> <ol> <li v-for="(todo,index) in todos"> {{ index }} {{ todo.text }} </li&g ...