News for hackers. Stuff that matters.
Re:A toddlers guide to memory leaks in JavaScript by kbart on Monday February 05, 2018 @04:24AM (#16307653)
This article does a really poor job explaining what memory leak is and barely even mentions JS specific pitfalls (what could be expected by reading a title).
Re:A toddlers guide to memory leaks in JavaScript by kushan2020 on Monday February 05, 2018 @06:41AM (#16308187)
It is called toddlers guide for a reason. It’s meant to be a very gental introduction and I try to avoid going knees deep into the topic. There are references to other great articles which tell you about pitfalls.
Re:A toddlers guide to memory leaks in JavaScript by marcusarmstrong on Sunday February 04, 2018 @11:45PM (#16306657)
This is just “using lots of memory”, not a “leak”.
Re:A toddlers guide to memory leaks in JavaScript by kushan2020 on Sunday February 04, 2018 @11:51PM (#16306679)
If you careful read the code ``` function sayHi() { var allNames = []; return name => { allNames.push(name); return ' ' + name; } } ``` It leaks memory on every invocation of the returned function
Re:A toddlers guide to memory leaks in JavaScript by taneq on Monday February 05, 2018 @12:00AM (#16306702)
In the context of a language with a working garbage collector, doesn't "memory leak" just mean "accidentally using lots of memory"?
Re:A toddlers guide to memory leaks in JavaScript by AstralStorm on Monday February 05, 2018 @03:36AM (#16307462)
With cyclical references add "freed sometime between now and eternity".

If this is not a definition of a memory leak I don't know what is.

Re:A toddlers guide to memory leaks in JavaScript by taneq on Monday February 05, 2018 @04:17AM (#16307630)
Well no, cyclical references only stop the object from being deleted if it's still accessible. That's what the 'mark' part of 'mark and sweep' does - it marks all objects still accessible somehow from inside the program. Then the 'sweep' bit runs through all allocated blocks and frees the unmarked ones.

Now, if you're merely approximating garbage collection with reference counting then sure, you have a problem.

Re:A toddlers guide to memory leaks in JavaScript by tehlike on Monday February 05, 2018 @02:46AM (#16307271)
Just monitor your production memory profile, and occasionally run load test on your app. It is fine.
Re:A toddlers guide to memory leaks in JavaScript by spentdeath on Sunday February 04, 2018 @11:40PM (#16306638)
All of these issues could’ve been avoided if we didn’t use functional programming. I think imperative languages are better because things like memory leaks and algorithmic errors are easy to conceptualize in the first place, hence less chance of typos.
Re:A toddlers guide to memory leaks in JavaScript by myhf on Sunday February 04, 2018 @11:47PM (#16306665)
All of these issues could’ve been avoided if we didn’t use imperative programming. I think functional languages are better because things like memory leaks and algorithmic errors are easy to conceptualize in the first place, hence less chance of typos.