Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

224
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda