Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

231
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!