Understanding the utilization of memory in the Chrome task manager

My investigation into a memory leak in a large JavaScript app, running as a widget in a browser with webkit and sfx (JavaScript core engine), led me to discover that the source of memory increase over time was $.ajax(..).

I experimented with different versions of jquery and tried using XMLHttpRequest directly, but still encountered the same issue. When I tested it on Google Chrome, I was surprised to find that the heap profiler did not show an increase in the number of JS objects or heap size. However, the Chrome task manager did indicate a growth in memory and private memory consumption. The code snippet I used for testing is:

var Main = {};
var xhr = new XMLHttpRequest();

function makeRequest() {
    xhr.timeout = 2000;
    xhr.ontimeout = function() {
        xhr.abort();
    }
    xhr.onreadystatechange = function() {
        if (xhr.readyState != 4) return;
    };

    xhr.open("POST", "", true); //async post request to local server
    xhr.send("{}");
}

Main.onLoad = function()
{
    setInterval(function() { makeRequest(); }, 3000);
}

Is this behavior normal? Could it be indicative of a native memory leak?

P.S. I am using Chrome version 35.0.1916.153 on Windows 7 Enterprise.

Answer №1

As outlined in the specification, the XMLHttpRequest object will not be automatically garbage collected.

4.2 Garbage collection

An XMLHttpRequest object will remain in memory if it is in the state of OPENED with the send() flag set, or if its state is HEADERS_RECEIVED or LOADING with certain event listeners registered as specified.

If an XMLHttpRequest object is garbage collected while the connection is still open, the request must be terminated by the user agent.

An informative article discusses this issue and suggests clearing references to the host object in callbacks using xhr = null after xhr.send(). It's important to note that in the provided example, there doesn't seem to be a leak since new xhr objects are not being allocated or used for results. The article also emphasizes that solely relying on chrome task manager may not detect leaks effectively.

It's recommended to utilize Chrome's devtools for diagnosing memory leaks by triggering manual GC and ensuring memory remains stable. If a memory leak is identified, devtools can assist in identifying unneeded objects still retained in memory (as explained further in the referenced tutorial).

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

Automating testing with WebdriverIO in scenarios where JavaScript is turned off

Is it possible to launch the browser with JavaScript disabled in the WebdriverIO framework? I am looking to automate a scenario that requires JavaScript to be disabled. However, when I try to disable JavaScript manually in Chrome or Firefox and run WDIO s ...

Running a child process in the browser using Node.js with the help of browserify

Utilizing browserify to enable node.js functionality in the browser, I am attempting to run a child process in my index.js file: var exec = require('child_process').exec; //Checking the installed node version var ls = exec('node -v', f ...

Is it possible to run a Vue file autonomously, similar to an HTML file

When it comes to running html, we can rely on mainstream browsers such as Chrome. But is there a similar tool for vue files, like the browsers designed for html? ...

including a content tag into an input field within a template

I'm experimenting with the new html5 template tag to create a versatile form that can be used in various situations without relying heavily on javascript. Check out this fiddle to see what I have so far http://jsfiddle.net/684uH/ My objective is to ...

The responsive navigation menu expands

Struggling with my responsive menu issue here. I must admit, I am not a coding expert by any means, but I've been tasked with web design responsibilities at work. The problem at hand is that the website isn't fully responsive, except for the "ar ...

Pressing Enter triggers Submit button twice

I’m currently working on a form that includes client-side JS validation using AJAX. The form is a simple contact form with three fields: name, email, and message. If you attempt to submit the form without proper validation, error message divs will appear ...

How can I prevent v-model from filling multiple fields?

Having just started with Vue.js, I've managed to solve most of the issues I've encountered so far, but there's one that's stumping me. I'm working on displaying a list of posts fetched from an API and I want to include a comments ...

The Radio button and Checkbox values are causing an issue where the Radio button is continuously summing upon clicking without a limit. Why is this happening? Check out

I'm currently stuck in a function and believe it would be helpful for you to guide me along the correct path. My goal is to sum the values of checked boxes with the values of checked radio buttons. However, the radio values are continuously accumulat ...

What is the best way to eliminate an item from an array in JavaScript or AngularJS?

I'm attempting to eliminate objects from an array and retrieve the resulting array. I've been using a remove function, but it's not functioning as expected. Here is the input I'm working with: The goal is to remove all values in the ar ...

What is the method in Plain/Pure Javascript for identifying the available properties and methods of an element object?

Is there a way to uncover all available methods and properties for an element object using only vanilla JavaScript, excluding jQuery? For instance, if I am working with the body object - document.getElementByTagName('body')[0] How can I retrieve ...

arrange objects based on their position using javascript

In my JavaScript code, I am trying to position objects above each other relative to a center point at coordinates 0,0. The number of objects, their sizes, and the spacing between them are all variable. This image illustrates my situation best (hopefully ; ...

What is the best way to show a block of text when hovering over an image with a smooth easing effect

How can I make a block of text appear with ease when hovering over an image of a tree? The current setup works, but the transition effect is not as smooth as I want it to be: HTML: <p id="hover-text1" class="hover-text1"> Accomplished! </p> & ...

If the div element undergoes a change, use an if-else condition to populate the data fields accordingly

I'm looking to create a basic if/else statement in JavaScript that checks if a div element has changed before populating JSON data fields/variables that pull from dynamically updated HTML. I want to avoid using the deprecated DOMSubtreeModified metho ...

Mobile video created with Adobe Animate

Currently, I am designing an HTML5 banner in Adobe Animate that includes a video element. However, due to restrictions on iPhone and iPad devices, the video cannot autoplay. As a workaround, I would like to display a static image instead. Can anyone provid ...

What information is displayed on the visible class roster?

I'm feeling a bit lost with this. element.classList.add('visible'); Can someone clarify what the 'visible' in this code snippet is? Is it an event or something else? Appreciate your help! ...

Could the autofill feature in Chrome be turned off specifically for Angular form fields?

Even after attempting to prevent autofill with autocomplete=false and autocomplete=off, the Chrome autofill data persists. Is there a method to disable autofill in Angular forms specifically? Would greatly appreciate any recommendations. Thank you. ...

The results from utilizing Mongoose's text search feature are inaccurate and not matching the expected

Currently, I am in the process of developing a recipe blog website using Mongoose, Node.js, and Express. However, I have encountered an issue with the text search functionality not producing the desired output. In my Recipe.js schema, I have included spec ...

Incorporating a swisstopo map from an external source into an Angular

I am looking to integrate a swisstopo map into my angular 8 app. As I am new to angular, I am unsure how to include this example in my component: I have tried adding the script link to my index.html file and it loads successfully. However, I am confused a ...

Improving the retrieval of API data using personalized React hooks when searching by modifying keywords

I'm just starting out with React Hooks and recently wrote a small code snippet that displays a list of courses to users. This code includes two main components, CourseList and Course, as well as a custom hook called useCourseList. Here's the code ...

Struggling with date validation as a new MomentJS user

Looking to validate a date in string format using moment JS, I am encountering an issue. Using the dd/mm/yy format in pCalendar in ngPrime, I store the date value in stDate. Here is the code I have written: var stDate = '02/02/2021'; var stDate ...