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

215
Vistas
Does referencing a child object prevent the parent object from being garbage collected in javascript

Say I have an object

let a = {
  b: {
    name: "Sugarcane"
  }
}

and I do

let c = a.b

and I later nullify the a object like so:

a = null

does the reference to b object by c prevent the previous object stored in a from being garbage collected in Javascript?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Actually no, as long as there is a reference to the object stored in memory, the GC will not be able to free this object from memory.

When you nullify object A it is removed from memory, but this does not affect its properties if they are objects and are stored in another variable.

You are just changing the reference from A to NULL, but B will continue to exist in memory as long as C continues to have its reference stored.

B will only be removed from memory when C is nullified.

let a = {
    b: {
        name: "Sugarcane"
    }
};

let c = a.b;

a = null;

console.log(
    "A value: ", a,
    "\nC value:", c,
    "\nC.name value:", c.name
);

about 4 years ago · Juan Pablo Isaza Denunciar
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