The memory leak dilemma triggered by fluctuating iframe src updates

Exploring the dynamic alteration of the src attribute within an <iframe> embedded in a Vue template led to a concerning discovery. The test involved changing the src every second, which ultimately resulted in 88% of available memory being consumed on a Windows 10 Machine with 32 GB Memory and Firefox Browser, eventually causing the computer to freeze.

Prior to this, similar issues were observed on a Raspberry Pi 4 (4GB) using chromium-browser. Switching between multiple vue components containing iframes caused memory leakage over a few days, leading to crashes with the infamous "he's dead jim" smiley face.

Below is the snippet of code used for the test:

<template>
  <div id="app">
    <iframe :src="src" />
    {{ count }}
    {{ src }}
  </div>
</template>

<script>
export default {
  data() {
    return {
      src : "",
      source : [
        "https://example.com/embeddedcontent/1",
        "https://example.com/embeddedcontent/2",
        "https://example.com/embeddedcontent/3",
        "https://example.com/embeddedcontent/4"
      ],
      count : 0,
      interval : null
    }
  },
  mounted() {
    const interval = setInterval(() => {
      this.src = this.source[ this.count % this.source.length ];
      this.count = this.count + 1
    }, 2000);
    this.interval = interval;
  },
  beforeDestroy() {
    clearInterval(this.interval);
  }
}
</script>

Observations

  • Consistent memory leaks across different systems and browsers (Win10/Firefox, Raspbian/chromium-browser)
  • Memory issues persisted during development (HMR) and production builds from Vue
  • Unknown nature of iframe content due to ability to set the src property to any URL

Solutions Needed

Considering only browser tab refreshes as a temporary fix, there must be alternatives to using iframes for external website content integration within a Vue App. Is there a method to completely clean up the iframe without leaving residual effects?

Update 2021/02/25

Further testing with Edge Browser exhibited the same increasing memory consumption trend. Firefox Private mode showed minimal impact. No disparity between production and development builds was noted. Additionally, a vanilla electron app script without Vue demonstrated similar rapid memory growth.

Answer №1

Let's delve into the inner workings of iframes in browsers - check out this article for more information: Detached window memory leaks

  1. When troubleshooting memory leaks, always utilize "incognito mode" to prevent any interference from browser extensions. Extensions might hold onto references within an iframe, keeping unnecessary data active. In Chrome, switching to incognito mode during profiling significantly reduced memory consumption and retention...

  2. Avoid using Vue CLI/Webpack dev mode for debugging memory leaks. Webpack's hot module reloading (HMR) can impact memory usage. Stick to production builds for accurate results...

  3. Note that JS runtimes like V8 store metadata about executed code in the JS heap. What appears to be a memory leak could actually be virtual machine metadata, as explained in this article: Feedback vectors in heap snapshots...

UPDATE: After conducting tests on my development setup (Ryzen 5 3600, 32GB RAM, Windows 10 x64), loading your example with 1-second intervals in Firefox Developer Edition v86.0b9 (64-bit) Private window (no extensions), here are my findings:

  1. With Dev Tools open and Memory profiling enabled (including recording call stacks), there was no noticeable increase in JS heap allocation after 40 minutes. A minor 60MB increase in Browser's Private Bytes was due to Dev Tools, which was promptly cleared upon closing the tool...

  2. Running the same example without opening Dev Tools for 40 minutes did not show any memory increment either...

Based on these observations, it seems there is no evident memory leak associated with iframes or Vue itself. If experiencing drastic memory usage spikes such as "Within a couple of minutes, my available memory was used by 88%," it's advisable to inspect your system configuration and browser extensions...

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

Ensuring Security: Incorporating Authentication Tokens in $resource Requests with AngularJS

I am looking to include an authentication token when making requests to my API for resources. I have set up a service using $resource: factory('Todo', ['$resource', function($resource) { return $resource('http://localhost:port/t ...

Converting a jQuery DOM element into a string representation

Currently, I am working with a textarea that contains the contents of an HTML file. This textarea includes all elements of my HTML page such as doctype, head, html, etc. My goal is to save the content of the textarea into a DOM variable using $.parseHTML: ...

Mastering the art of square bracket destructuring in React through deep comprehension of the concept

import React, { useEffect, useState } from 'react' import { Text } from 'react-native' export default function Counter() { const [count, setCount] = useState(0) useEffect(() => { const id = setInterval(() => setCount((co ...

Configuring Node.js HTTPS to function alongside HAPROXY

My goal is to establish communication between my nodejs app and HAPROXY using HTTPS. The plan is for nodejs to send a message to haproxy via https, and haproxy will then route the message accordingly. Initially, I had success with the request.js library, ...

Decoding json data with targeted API keys

Looking for some assistance here. I've got a JSON data set that looks like this: [ { "positive": 2, "negative": 4 }, { "positive": 9, "negative": 18 }, { "positive": 6, "negative": 12 } ...

Obtain the name of a node using its identification number in D3JS

I am currently working on implementing a generalized tooltip feature. This tooltip will display the name and other relevant data of the active node. For example, if node 3 is currently active, the tooltip will show the name and distance (not link distance) ...

Guide to stopping available times from cycling through an array with the help of watch功能?

I am currently developing a booking application within Vue CLI. I have made use of vue-ctk-date-time-picker for selecting the date and time. My goal is to disable certain times based on the chosen date, but I am encountering an issue. The code I have writt ...

Exploring the Power of Filtering Arrays in JavaScript

Currently, I am enrolled in online JavaScript courses and I'm intrigued by a particular task: In this task, we are given an initial array (the first argument in the destroyer function) followed by one or more arguments. The goal is to eliminate all e ...

The JavaScript loop does not update the value of a number input field

In an effort to save and retrieve data from local storage, I have implemented a loop that iterates through various fields in a dynamic table row. The process involves saving the data to local storage, clearing the table rows, recreating them for data retr ...

When submitting the form, set the value to "null" if the input field is left empty

I am new to the form validation process and need help returning a value of null if the input value is an empty string upon form submission. In the example below, there are three options for verifying a user's identity. Depending on the selected radio ...

Utilizing i18n's useTranslation and Redux's connect Higher Order Components to export components efficiently

My application has been utilizing Redux for quite some time, with the component exports structured like this: export default connect(mapStateToProps, mapDispatchToProps)(MyComponent); Now, I am integrating an i18n translation library and would like to use ...

What causes the discrepancy in the output of `document.documentElement.childNodes` in JavaScript?

While working on my code exercise today, I came across a special case regarding the "document.documentElement.childNodes" property. Originally, I believed it to represent all child nodes within a tag as before. However, when implementing my code, I noticed ...

Refreshing the child route page does not display the specific data assigned to that particular route

I have everything set up on codesandbox. Any assistance would be highly appreciated. // Here is the link to my Axios Getter in /year methods: { async fetchData() { const self = this; const response = await axios.get( "https://e ...

Transferring a document through an HTML form to PHP using JavaScript

I've developed a JavaScript form but I intentionally omitted the submit button since it consists of just one input field. Instead, I utilized the onchange function to achieve this. Here's what my form structure looks like: <form method="post" ...

Send a JsonArray via Ajax

Struggling with posting a JSON Array to SENDGRID using Ajax. Postman works fine, but encountering error (bad request = missing parameters) in my .js file. Any assistance would be greatly appreciated. Note: The values are valid, sensitive information has ...

Raphael and Safari: The Perfect Pair

Lately, I've been working on a project using Raphael 2.0.1 and after running some cross-browser checks, I noticed that text is not displaying correctly in Safari. It seems like the 'dy' attribute is inheriting the value of the 'y' ...

Tips for utilizing $rootScope define within one angular service in another service with typescript

Within a service class, I have initialized a $rootScope in the constructor and assigned a property to it using this.$rootScope. However, when attempting to access this property in another service within the same class, a new $rootScope is created and the p ...

Converting Node.js Date.toString() output into a time format in Go

My go service is currently receiving data from an external source. Here's how the data appears (in JSON format)- { "firstName": "XYZ", "lastName": "ABC", "createdAtTimestamp": "Mon Nov 21 2 ...

Issues with form submission and JavaScript functionality have been detected in Internet Explorer, Firefox, and Safari, but are functioning properly in Chrome

Hey there! I've encountered a puzzling issue with a form I've created. It's programmed to determine the next page to redirect to using JavaScript after submission. Oddly enough, everything functions perfectly when I test it out in my IDE (C ...

Obtain the VW/VH coordinates from an onclick action in JavaScript

With this code snippet, you'll be able to retrieve the x and y coordinates of a click in pixels: document.getElementById("game").addEventListener("click", function(event) { console.log(event.clientX, event.clientY); }); However ...