Browser freezes unexpectedly every 10-15 minutes

I have an application that displays 10 charts using dygraphs to monitor data. The charts are updated by sending ajax requests to 4 different servlets every 5 seconds. However, after approximately 10-15 minutes, my browser crashes with the "aw! snap" message. What could be causing this issue? Could it be a problem with the JavaScript code or the frequency of the requests?

Browsers tested: Firefox and Chrome.

Note: Upon refreshing the browser after the crash, everything works fine again for another 10-15 minutes.


JavaScript code:

var i=0;
var loc = new String();
var conn = new String();
var heapUsage = new String();
var cpuUsage = new String();
var thrdCnt = new String();
var heapUsageConsole = new String();
var cpuUsageConsole = new String();
var thrdCntConsole = new String();
var user = new String();
var MemTotal = new String();
function jubking(){
    // XMLHttpRequest logic here
}

Answer №1

If your Firefox browser is crashing, you can use the about:crashes feature to see why it's happening. One possible reason could be memory leakage from not properly clearing data variables after an AJAX call.

An Update:

It seems like the amount of memory being used (1,923,481 K) is way too high, indicating a definite data leak issue. What operating system are you using? If on a *nix system, running Firefox from the console might provide more information on what's causing the crash. For Windows, there might be other ways to troubleshoot.

You might want to try reducing poll intervals and debug through tools like Firebug or Chrome's debugger to pinpoint where the problem lies. In case of severe crashes, start commenting out portions of code until you isolate the exact cause and then work on fixing it. Good luck!

Answer №2

It appears that the issue you are experiencing may be related to how you are using dygraphs, as mentioned in your comments. Instead of continually binding new graphs, it seems like you only need to update the data and implement a moving window for better performance. Consider adjusting your updater with this pseudo-JavaScript code snippet:

var graphs = {
    dbLocks: {
       graph: new DyGraph(/* ... */),
       data:  [ ]
    },
    activeConnection: {
        graph: new DyGraph(/* ... */),
        data:  [ ]
    },
    // additional graphs
};

var DATA_WINDOW_SIZE = 1000; // Adjust accordingly.

function update(which, new_data) {
    var g = graphs[which];
    g.data.push(new_data);
    if(g.data.length > DATA_WINDOW_SIZE)
        g.data.shift();
    g.graph.updateOptions({ file: g.data });
}

function jubking() {
    // Make AJAX calls and assign callbacks to handle updates.
    // Once all AJAX calls are complete, restart the timer.

    setTimeout(jubking, 5000); // Repeat every 5 seconds.
}

The key is to limit the amount of data stored by using a window approach to prevent memory consumption issues. By setting a maximum width for your data cache, you ensure that old data points are removed as new ones are added, maintaining a manageable size.

To address multiple asynchronous AJAX calls completion, refer to this resource: How to confirm when more than one AJAX call has completed?

Answer №3

The suggestion provided above emphasizes the importance of reusing your Dygraph object and utilizing g.updateOptions({file:...}) to minimize memory usage, which is a highly effective approach.

Alternatively, you can opt to use g.destroy() prior to redefining the Dygraph object. This action prompts dygraphs to clear out its internal arrays and DOM references completely. Here's an example:


g = new Dygraph(...);
g.destroy();
g = new Dygraph(...);

To learn more about preventing Dygraphs memory leaks, please visit:

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

A guide on extracting split values and assigning them to individual variables

Currently, I'm working on a project utilizing node.js, express, mongo, and socket.io. After successfully retrieving geolocation coordinates and storing them in a hidden input field, I encountered an issue when attempting to save the data into the data ...

Utilizing onClick with material-ui button - functioning flawlessly for a single interaction

I have been attempting to encapsulate a Material-UI button within another component. Everything seems to be working well, except for when I try to handle the onClick event - it appears to only work once. Here is an example that demonstrates the issue: ht ...

npm ERROR! 404 Content removed by unidentified source on August 8, 2022 at 09:20:35.527 UTC

Upon running the command <npm view e-biz-znnf versions --json> in the terminal, npm throws an error message: npm ERR! code E404 npm ERR! 404 Unpublished by undefined on 2022-08-08T09:20:35.527Z npm ERR! 404 npm ERR! 404 'e-biz-znnf' is no ...

Instead of automatically playing, Youtube videos either remain idle or display suggested videos

I am trying to play a specific moment of an embedded Youtube video using some javascript code. At the specified time, I execute the following code: document.getElementById("video").src= "https://www.youtube.com/embed/...?autoplay=1&start=212"; where ...

The functionality of ng-click and ng-submit seems to be malfunctioning

I am currently facing an issue with my Angular application and PhoneGap. I have a login form along with a login controller set up, but for some reason, the ng-submit function is not working as expected. When the submit button calls the formConnexion() func ...

What is the best way to incorporate a class creation pattern in Typescript that allows one class to dynamically extend any other class based on certain conditions?

As I develop a package, the main base class acts as a proxy for other classes with members. This base class simply accepts a parameter in its constructor and serves as a funnel for passing on one class at a time when accessed by the user. The user can spe ...

Saving a JSON object to a JSON file

My code successfully utilizes the following structure: $.getJSON('Json_users_templates/SO_example.json', function(data) { }); to retrieve JSON data from a local .json file into an object. Now, I am looking for some code that will allow me to s ...

How to efficiently use Yii2 and Ajax to insert data into a table twice in one

My form in Yii2 Advanced is inserting data twice into the table. When I click the submit button twice, the form inserts the data into the table twice as if I clicked the submit button two times consecutively. I am using ajax to submit my form. The code for ...

Is it possible for the Chrome mobile camera to take up the full screen size on

Currently, I am using the code below to access the camera and display the stream. The width of the element is 100%, but the height seems to be around 70%. Is there a better way to make it fill the entire screen? HTML <video autoplay class="screen"> ...

Using jQuery to create dynamic elements that fade out with timers

My website has a simple message system that displays messages in a floating div at the top of the page. Each message is supposed to fade out after a certain amount of time, but I want users to be able to pause the fading process by hovering over the messag ...

Removing a modal div element in React after navigating

import React, { useState } from "react"; import { useNavigate } from "react-router-dom"; import axios from "axios"; import Cookies from "js-cookie"; const LoginPage = () => { const [email, setEmail] = useState( ...

Fetch solely the metadata from HTML5 video and audio files

Before we dive in, let me address a question I have regarding video metadata loading without any additional video content. The preload = "metadata" attribute doesn't seem to be functioning as expected. My testing thus far has been limited to Win Chrom ...

Enabling the submit button only when text is entered in the text fields using jQuery

I have a script that automatically submits a form when two textfields are filled using variables from local storage. The script checks if the variables for email and password are not null before submitting. if (localEmail != null && localPwd != null) { ...

Add an item to an array that contains objects within an array of other objects

How can I properly push the values "label" and "link" into an object within "data" based on the id match with the "parent" value of another object? The goal is to insert these values into the "children" property of the corresponding target object, but it d ...

Extracting live TV channels from an m3u file by differentiating them from VOD content

Currently, I am developing an IPTV player app and have successfully parsed the m3u file. My current challenge is separating live TV channels from Video on Demand (VOD). I am unsure of where exactly the transition happens in the playlists. Below are the ke ...

Problem with reordering rows in a PHP DataTable

While attempting to retrieve data from a database table and display it in a DataTable, I encountered the following error: DataTables warning: table id=example - Invalid JSON response. To learn more about this error, refer to http://datatables.net/tn/1 ...

Ways to bring in external javascript files in reactjs

I'm currently working on a form that requires the user to input their location. To achieve this, I have integrated the npm package react-geosuggest-plus. However, I want to avoid including <script src="https://maps.googleapis.com/maps/api/js?key=AI ...

parsing an array using jQuery's getJSON

Finally got the simplified array to work, check it out below If you're still struggling with parsing a complicated array, you can refer to this link. TLDR: I need to extract and insert each heading from an array into a div using Jquery - getJSON, wi ...

What could be causing the NoScript tag to malfunction across different web browsers?

I've incorporated the NoScript tag into my JSP pages in the head section. To avoid conflicts with tiles, I made sure not to include multiple NoScript tags. However, I am experiencing issues in Internet Explorer where it doesn't seem to be working ...

Automatically add values after successful Facebook login

Currently, I am working on a Cordova project where I have implemented Facebook login for user authentication. While the login is functioning correctly, I am facing an issue where I need to manually press a button with the ID getinfo in order for the values ...