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

181
Views
why did console.log seem to cause memory leaks in Chrome?

I have a function a where there is a function b that references foo in its closure.

class Foo {}

function a() {
  const foo = new Foo()
   const b = () => {
        foo // referencing `foo`
    }
    b()
};

a() // no memory leaks

after I executed a, there are no memory leaks for Foo.

I also tweaked it slightly. Still, no memory leaks for the following examples.

class Foo {}

function a() {
  const foo = new Foo()
   const b = () => {
        if(foo === 'foo') {
            
        }
    }
    b()
};
a() // no memory leaks

class Foo {}

function a() {
  const foo = new Foo()
   const b = () => {
        console.log(foo.lol)
    }
    b()
};
a() // no memory leaks

But as soon as I logged out foo, it causes memory leaks.

class Foo {}

function a() {
  const foo = new Foo()
   const b = () => {
        console.log(foo)
    }
    b()
};
a() // memory leaks

enter image description here

My question is why console.log(fii) leaks but referencing foo in other ways or log out its property console.log(foo.lol)

I tested these in Chrome 103 DevTool console.

about 4 years ago · Santiago Gelvez
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!