formkit / auto-animate

A zero-config, drop-in animation utility that adds smooth transitions to your web app. You can use it with React, Vue, or any other JavaScript application.
https://auto-animate.formkit.com
MIT License
11.96k stars 210 forks source link

Memory Leak #180

Open reitowo opened 7 months ago

reitowo commented 7 months ago

Assume this template:

<div v-auto-animate class="flex flex-column flex-grow-1"
             :style="{ gap: `${conf.style_quest_spacing / 16}rem` }">
  <StageSongItem :song="song" :config="conf" :index="index + 1" v-for="(song, index) in songs" :key="song.db_id"/>
</div>

In javascript, this triggers every second.

const getActiveSongs = async () => {
  const ret: { songs: Song[], finished: number } = (await axios.get('/api/song/active')).data
  songs.value = ret.songs
  finishedCount.value = ret.finished
}

It is observed that this function is called every time the songs.value is set image

the forEach will setTimeout on every el children, and doesn't clearTimeout, which will create thousands of thousands closure and callbacks, and leads to memory leak. image

This replacement of array is common in vue design. image

So, in theory, any update frequency less than 2s will cause the memory go insane eventually. In fact the intervals is never get clearInterval either, so that is another leak point.

In conclusion, auto-animate doesn't work with changing items (for a long runtime)