megasanjay / vue3-lottie

A simple Vue 3 component for using Lottie animations in Vue 3
https://vue3-lottie.vercel.app/
MIT License
359 stars 35 forks source link

The bug that excessively occupies system memory seems to indicate a memory leak issue. #531

Closed kustone closed 2 months ago

kustone commented 5 months ago

In the Windows/Nuxt3 v11 environment, I found that the vue3-lottie component renders using SVG, and when I enable autoplay and infinite looping, the memory usage within the tab spikes to 500-2000MB, significantly occupying system memory. This seems to indicate a memory leak issue. When I stop using the vue3-lottie component, the memory usage returns to normal. This problem was not present when using the Vue2 version previously.

kustone commented 5 months ago

I seem to have found the root cause of the problem, which lies in the code of the lottie-web package. When using both the vue3-lottie and lottie-web libraries with SVG rendering and enabling loop looping and autoplay, the browser tab consumes around 200MB of system memory after page load, gradually increasing to 500-900MB or higher within 10 seconds. Sometimes, the browser's memory recycling mechanism doesn't work effectively, and even when it does, it only maintains around 400MB, or repeated refreshes cause memory overflow, leading to page lagging or crashing.  However, when I use the script tag to import lottie-player.js, under the same conditions mentioned above, the memory stays at around 150-200MB after page load. Then, after the browser's memory recycling mechanism triggers, it stays around 73MB, and the aforementioned bug does not occur. Below is my solution, hoping it can help everyone avoid wasting a lot of time and effort on this issue!  My project: NUXT (v3.11) + Vue3 + ArcoDesign System environment: Windows 11, EDGE/Chrome browsers Solution:  Stop using vue3-lottie and lottie-web (because they currently have bugs). Online import or download and locally import: https://unpkg.com/@lottiefiles/lottie-player@latest/dist/lottie-player.js You can refer to my Nuxt component below, hoping it can help you!

<template>
  <div>
    <lottie-player ref="lottie" src="/image/lottie/4MMSzbLIE3.json" background="transparent" speed="2"
          style="width: 300px; height: 300px" direction="1" mode="normal" loop autoplay></lottie-player>
    <a-space>
      <a-button type="primary" @click="lottie.play()">播放</a-button>
      <a-button type="primary" @click="lottie.stop()">停止</a-button>
    </a-space>
  </div>
</template>

<script setup>
import "assets/js/lottie-player.js";
const lottie = ref(null);
const stop = () => {
  lottie.value.stop();
};
</script>

<style lang="less"></style>

QQ截图20240324190737 D124D95415C116B45DC749849E1455C2

megasanjay commented 5 months ago

Thanks for bringing this up. I would suggest using the browser management tool to see if you see the same results. Just trying it on pages that have with infinite lotties showing and against the Nuxt.com homepage I see the same numbers:

image

megasanjay commented 5 months ago

It's my 404 page that has a lottie on it that I'm using to check. Actually it runs lower image

megasanjay commented 5 months ago

@kustone Please let me know with your results

megasanjay commented 5 months ago

My examples page has a much higher footprint but this can be attributed to over 10 lotties being rendered all at once with varying levels on interaction on them: image

megasanjay commented 5 months ago

For the task manager results:

Only this github issue page opened. image

This github issue page + nuxt homepage image

This github issue page + a page with a lottie opened. image

I'm not seeing giant swings like you here

github-actions[bot] commented 4 months ago

This issue is stale because it has been open for 30 days with no activity.

alessiochiffi commented 4 months ago

I've also experienced the same issue with vue3-lottie on nuxt 3, with chrome crashing the page due to a memory leak.

megasanjay commented 4 months ago

@alessiochiffi Do you have a copy of the website/lottie for this. Would be something worth looking into

alessiochiffi commented 4 months ago

Unfortunately it's a private repo and we ended up removing the Lottie implementation from the site due to this issue. I will try to replicate and share it here as soon as I can

github-actions[bot] commented 3 months ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 2 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.