Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

258
Vistas
nuxt/vue memory management and destroyed life cycle

I have two page components and each one has two local data ... in "created" life cycle I assign some value to these data then I change route between these two pages ... from the memory tab in developer tool I can see heap memory size will increase with each route change but as far as I know vue should remove all data related to destroyed component but that's not the case here.

~/pages/index.vue:

<template>
  <nuxt-link to="/contact">contact</nuxt-link>
</template>
<script>
export default {
  data() {
    return {
      testArr: [],
      str: "...", //assign very large string 
    };
  },
  created() {
    for (let i = 0; i < 100000; i++) {
      this.testArr.push({ //just to make this array as big as possible
        key1: this.str,
        key2: this.str,
        key3: this.str,
        key4: this.str,
        key5: this.str,
      });
    }
  },
  destroyed() {
    //although we are inside destroyed life cycle we can still access to 
    //this.str,this.testArr
    console.log("destroyed");
  },
};
</script>

~/pages/contact.vue:

<template>
  <nuxt-link to="/">home</nuxt-link>
</template>
<script>
export default {
  data() {
    return {
      testArr: [],
      str: "...", //assign very large string 
    };
  },
  created() {
    for (let i = 0; i < 100000; i++) {
      this.testArr.push({ //just to make this array as big as possible
        key1: this.str,
        key2: this.str,
        key3: this.str,
        key4: this.str,
        key5: this.str,
      });
    }
  },
  destroyed() {
    //although we are inside destroyed life cycle we can still access to 
    //this.str,this.testArr
    console.log("destroyed");
  },
};
</script>

***if I add bellow code to both of these pages now memory will not increase but vue should release memory by itself and inside 'destoryed' life cycle 'this.<some-data' should be undefined:

beforeDestroy() {
    this.str = undefined;
    this.testArr = undefined;
  },

how can I optimize my app to release memory when component gets destroyed and not hold data related to the destroyed component in memory?

nuxt version "2.15.8"
vue version "2.6.14"

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda