question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Memory Leak on route navigation

See original GitHub issue

Environment


  • Operating System: Linux
  • Node Version: v16.14.2
  • Nuxt Version: 3.0.0-rc.12
  • Nitro Version: 0.6.0
  • Package Manager: npm@7.17.0
  • Builder: vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://v3.nuxtjs.org/getting-started/introduction

Describe the bug

repeatedly switch tabs from e.g. get started to guide and watch the memory increase. Fresh load image After 30 swaps image

Additional context

For bigger pages this results in 100s of leaked MBs within only a handful of route changes which in turn makes switching routes take seconds and is really bad user experience.

Logs

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

7reactions
danielroecommented, Oct 23, 2022

I often regret interim updates, but - 🤷 - my current hypothesis is that this is an issue with <Suspense> + <Transition> preserving the context in the pending branch, meaning every click handler (for example) preserves a reference to potentially thousands of removed DOM nodes.

Having entirely disabled <NuxtPage> and <NuxtLayout> in the Nuxt Movies project, I still get the behaviour with the following template. (If you want to replicate, you will also need to swap out the auto-imports of useRoute and useRouter to be from vue-router for as pure a Vue experience as possible).

<template>
  <div>
    <RouterView v-slot="{ Component }">
      <template v-if="Component">
        <Transition mode="out-in">
          <Suspense>
            <component :is="Component" />
          </Suspense>
        </Transition>
      </template>
    </RouterView>
  </div>
</template>

https://vuejs.org/guide/built-ins/suspense.html#combining-with-other-components

Removing <Transition>, either from the template above, or if using NuxtPage, via app.pageTransition and app.layoutTransition greatly reduces the issue in my testing (that is, in the Nuxt Movies repro, decreases leak from 1.7Mb per navigation to 70Kb). Nevertheless, there are still some preserved detached DOM nodes from the pending state of <Suspense> , which suggests that the real core issue here is coming from <Suspense>.

The next step is likely to attempt to reproduce using Vue without Nuxt to confirm my hypothesis.

Possible causes I’ve ruled out:

  • NuxtLink’s intersection observer implementation
  • NuxtLayout
  • NuxtPage and page progress hooks
  • useHead
4reactions
warflashcommented, Oct 23, 2022

Gotcha, got a pretty tight schedule today unfortunately but should I get to it I’ll post it here. Enjoy family time and the rest of your sunday!

Read more comments on GitHub >

github_iconTop Results From Across the Web

android - Memory leak with simple activities navigation
I launch my app, and let's say the memory usage is 1.1GB total out of my 2GB total memory. I click on a...
Read more >
Memory leak: How to avoid it in Vue js
To open the Chrome Task Manager on Mac, choose Chrome Top Navigation > Window > Task Manager or on Windows, use the Shift+Esc...
Read more >
Exiting an Angular Route - How To Prevent Memory Leaks
In this tutorial we are going to learn how we can accidentally creating memory leaks in our application while using the Angular router....
Read more >
Optimize memory usage and performance
Prior to 2.14.0, all screens are essentially regular native View in each platform, which will increase memory usage and make the render tree...
Read more >
Navigation Memory Leak - AI
I have 120 AI characters in a small, bare bones map. They do not have skeletal meshes and very little other logic.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found