Lottie-web experiences a memory leak

Currently implementing lottie web on my front-end, but encountering persistent memory leaks. The JavaScript VM instance remains below 10MB when lottie is removed altogether.

However, upon enabling lottie, the memory usage escalates rapidly whenever the page is refreshed or navigated to other pages, reaching levels from 30MB to 80MB and beyond, causing significant lag.

While I came across this particular issue, the suggested solution did not apply to me as my animations do not involve repeaters. Despite attempting the recommended approach with no success.

Feel free to explore the complete test website here.

NOTE: Vue is utilized along with a custom component for lottie animations.

<template>
    <div ref="animation"></div>
</template>

<script>
import lottie from 'lottie-web';

export default {
    data() {
        return {
            hover: false,
        }
    },
    mounted() {
        lottie.loadAnimation({
            container: this.$refs.animation,
            renderer: this.renderer,
            loop: this.loop,
            autoplay: this.autoplay,
            path: this.path, // Defines animation source
        });
    },
    props: { /* defined props */ }
}

Another attempt involved importing the animation directly:

import animation from '../../../../images/web/ilu-we-create.json';
...
mounted() {
    lottie.loadAnimation({
        container: this.$refs.animation,
        renderer: this.renderer,
        loop: this.loop,
        autoplay: this.autoplay,

        // AnimationData without deep copy
        animationData: animation,

        // AnimationData with deep copy
        //animationData: JSON.parse(JSON.stringify(animation)),
    });
},
...

Interestingly, the memory consumption remained consistent regardless of the method used.

If anyone has insights on how lottie handles memory allocation and suggestions to eliminate these memory leaks, your assistance would be greatly appreciated.

Many thanks in advance.

Answer №1

I encountered a similar issue and was able to resolve it (although I am not an expert in monitoring memory leaks)

When dynamically importing lottie and animationData, make sure to call both destroy methods: this.animation.destroy() and this.lottie.destroy()

...,
  async mounted () {
    this.lottie = await import('lottie-web').then(module => module.default)
    this.animationData = await import('~/path/to/animationData.json')
    this.$nextTick(() => {
      this.animation = this.lottie.loadAnimation({
        animationData    : JSON.parse(JSON.stringify(this.animationData)),
        loop             : false,
        autoplay         : true,
        renderer         : 'svg',
        container        : this.$refs.heroCanvas,
        rendererSettings : {
          progressiveLoad: false,
        },
      })
    })
  },
  beforeDestroy () {
    if (this.lottie) {
      this.lottie.destroy()
      this.lottie = null
    }
    if (this.animation) {
      this.animation.stop()
      this.animation.destroy()
      this.animation = null
    }
  },
...

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

Is Storybook webpack stuck in a loop, rebuilding and reloading constantly?

While working on a NextJS project with Storybook, I am encountering a recurring issue where the webpack keeps rebuilding continuously without stopping. This relentless rebuilding process puts a strain on my CPU and drains the battery of my device. Even aft ...

Combine array in MongoDB containing nested documents

I need assistance with querying my MongoDB database: Specifically, I want to retrieve data that is nested within an array and filter it based on a specific key within the nested structure. The example document looks like this: [ { "name": ...

JS Unable to get scrollIntoView function to work with mousewheel event

I have been working with the script provided above. It correctly displays the id in the browser console, but unfortunately, it is not triggering the scrolling function as expected. var divID = null; var up = null; var down = null; function div(x) { s ...

Combining data from an object within an array in JavaScript

I am looking for a way to incorporate values from an Object (weekdayMap) into an existing array (vehicleAvailabilities) that contains objects. I require the value Montag on day one and Dienstag on day two. This pattern continues for each day of the week. ...

What is the best way to use JavaScript to conceal a section of a form div?

After receiving some code from a certain platform and implementing it to hide part of my form div element, I noticed that the element hides and unhides quickly when running in a browser. This rapid hiding and showing behavior occurs when clicking on the bu ...

Encountering an unforeseen identifier error while attempting to install GitHub using

I am facing an issue with my GitHub repo where I am trying to install Clockwork SMS using npm. However, the console is showing an error message "Uncaught SyntaxError: Unexpected identifier". You can find the website here: . To explain further, I am workin ...

Activate all chosen CSS circles

I'm currently working on creating a progress bar using CSS circles. The idea is that when you click on each circle in sequence (1, 2, 3), all three circles and the line connecting them will fill up with red color. If you then go back (3, 2, 1), the co ...

Triggering a click event on an anchor <a> element

Seeking help with a Javascript event query. I have an <a> tag set up like this: <a id='aTag' href='http://example.com'>Click to redirect</a> When attempting to trigger the click event using: <script> $('#a ...

combine two 2D arrays in JavaScript

I am facing a challenge with this issue concerning 2D arrays. The task at hand is to create a JavaScript function called addArrays(al, a2) that accepts two 2D arrays of numbers, a1 and a2, and calculates their "sum" following the matrix sum concept. In oth ...

Node Express application experiences issues with Handlebars rendering additional empty objects from JSON arrays

Currently, I am attempting to retrieve data from a REST API call and display it as a list using Handlebars, which functions as my view engine in a Node Express App. Below is the route I am using: router.get('api/projects', function(req, res){ ...

Transform the JSON response from MongoDB into a formatted string

var db = mongoose.connection; const FoundWarning = db.collection('warning').find({UserID: Warned.user.id, guildID: message.guild.id}).toArray(function(err, results) { console.log(results); }) I have been attempting to ...

Using canvas transformation changes the way drawImage is applied

I have been working on a game as a hobby and you can find it at . I have managed to get most aspects of the game working well, such as transformation, selection, movement, and objects. However, there is one particular challenge that I am struggling with. ...

Is there ever a situation when it's acceptable to forego graceful degradation?

Currently, I am constructing a video-sharing CMS that heavily relies on jQuery and ajax for various functionalities such as rich UI effects and data submission/retrieval from the database. Unfortunately, if JavaScript is disabled, about 90% of the function ...

The initial drag function seems to be dysfunctional in vue-smooth-dnd for vuejs

Check out the code snippet below for a drag and drop section. The div with the class drag-block should be draggable, but it doesn't work on the first attempt; it only drops when we drag it for the second time. https://github.com/kutlugsahin/vue-smoot ...

Visualizing network graphs using JavaScript

I am in search of a JavaScript network visualization graph (not a chart) that can handle JSON input effectively. I have tried using the JIT infovis toolkit, RGraph, and space tree to display multiple levels in the graph. However, I have encountered issue ...

Techniques for implementing a PHP base_url() function in a JavaScript file

I need to pass base_url from the Book Controller to the book.js file This is the function within book.js function loadPage(page, pageElement) { // Create an image element var img = $('<img />'); img.mousedown(function(e) { ...

Templating with Underscores: Revolutionizing token markers

When using out of the box underscore templating, the default markers for raw content are <%= %>, and for HTML escaped content are <%- %>. However, it is possible to change these markers by adjusting the template settings, for example: _.templ ...

Bring in a JavaScript file to a Read-Evaluate-Print-Loop (

Currently experimenting on Windows 10 TP build 9926 with nodejs, I am attempting to import a JavaScript file into an active session of nodejs that is operating in the Windows command prompt. This will allow me to call functions from the imported script dir ...

What is the best way to handle processing large amounts of data stored in a file using JavaScript within the

Suppose my file contains the following data and is located at /home/usr1/Documents/companyNames.txt Name1 Name 2 Name 3 Countless names... I attempted to use this code: $> var string = cat('home/usr1/Documents/companyNames.txt'); $> s ...

Sending a multi-level property object to the controller in a post request

I am facing a challenge where I need to transfer an object from the view to the controller, and the model comprises a list of objects, each containing another list of complex objects. Let's consider the following models: public class CourseVm { p ...