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

233
Visualizações
How does memory leak happen from arrow functions

I have two methods below:

function foobar() {
   const viewState = getViewState();
   return () => { use(viewState); }
}

function foobar() {
   return (viewState) => { use(viewState); }
}

Can you please let me know if there is memory leak from any of these functions?

I was told by someone that the 1st method is leaking since the viewState is passed from outside and it is being held inside the closure without being released, whereas the 2nd function is not leaking because viewState is passed as a parameter.

If that's true, I am interested in more detailed explanation.

  • Why the 1st method is leaking memory? Is it because the program is unable to remove viewState from memory automatically after it executes the code inside the arrow function?
  • Why the 2nd method where passing viewState as parameter is not causing memory leak?
about 4 years ago · Juan Pablo Isaza
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