Live data from Hacker News

How JavaScript works: memory management and common memory leaks

blog.sessionstack.com

11–20 of 57 posts

Re: How JavaScript works: memory management and common memory leaks

#11

Who is this article written for? There's a whole section on "What is memory?". If you are optimizing to remove memory leaks I really hope you already know what memory is.

m with you pal, memory leaks are the last topic you touch when optimizing a function, usually you start lowering the execution time, followed by I/O blocking issues then proceed to server-related issues, network latency and after all that is covered you start looking for "memory leaks" so explaining memory is usually unnecessary at this point, since usually JR's devs are more focused on producing software rather than optimizing it.

IMHO memory leaks are important only on embedded software because you start there with a really low memory available for your software to run.

Re: How JavaScript works: memory management and common memory leaks

#12
post #2

having stuff do stuff for you is useful until it doesnt

I agree. I strongly dislike "magic" in programming. I prefer to call it "denial" because you need to know about the complexities anyway, and "magic" often means sweeping them all under the rug.

At some point every abstraction above Assemby meets that criteria though. The lines are personal and mostly arbitrary.

Re: How JavaScript works: memory management and common memory leaks

#13

Who is this article written for? There's a whole section on "What is memory?". If you are optimizing to remove memory leaks I really hope you already know what memory is.

m with you pal, memory leaks are the last topic you touch when optimizing a function, usually you start lowering the execution time, followed by I/O blocking issues then proceed to server-related issues, network latency and after all that is covered you start looking for "memory leaks" so explaining memory is usually unnecessary at this point, since usually JR's devs are more focused on producing software rather than…

It's also very important when building long-running applications (e.g. electron applications).

Re: How JavaScript works: memory management and common memory leaks

#14
Nice article. Minor gripe about the static vs dynamic memory section. The requirement that the data sizes be known at compile-time for static memory (with the example of an array allocated to a user-inputted size), seems to be based on a past restriction of the C language. C has since remove the requirement that stack-based arrays are sized with a compile-time constant; there is nothing at the hardware/assembly level which prevents such arrays. So these stack-based non-compile-time-sized arrays don't fit into either the static or dynamic memory categories presented here.

Re: How JavaScript works: memory management and common memory leaks

#15

Earlier quoted context omitted.

I agree. I strongly dislike "magic" in programming. I prefer to call it "denial" because you need to know about the complexities anyway, and "magic" often means sweeping them all under the rug.

At some point every abstraction above Assemby meets that criteria though. The lines are personal and mostly arbitrary.

Meh, if you try and split hairs, even assembly has magic in it nowdays. Not all instructions take the same amount of time. Some flush caches, thus cause unexpected memory behavior, etc.

However, I think it is fair that most people learn roughly what the side effects are of each line at a local level.

Ironically, this is an argument against many functional languages. There are not side effects of the logic, per se. However, there are massive implementation side effects that are not necessarily easy to reason on.

The saving grace for the vast majority of people is that typically you can get by without knowing all of this. The people that care, do care. But statistically you are not one of them. :)

Re: How JavaScript works: memory management and common memory leaks

#16
post #4

Wait, is #3 for real? If that's the case it seems like a huge oversight.

Yeah. I thought so too (and still think so).

SO post: https://stackoverflow.com/questions/19798803/how-javascript-...

Chrome bug report: http://crbug.com/315190

Meteor blog (linked in article): https://blog.meteor.com/an-interesting-kind-of-javascript-me...

Live example (will crash due to memory leak): https://s3.amazonaws.com/chromebugs/memory.html

---

The reason this exists in all JS engines is for performance; it's easier to have on context record instead of several.

Other languages do not do this. Off the top of my head: Lua, Java, Scala

Re: How JavaScript works: memory management and common memory leaks

#17
post #15

Earlier quoted context omitted.

At some point every abstraction above Assemby meets that criteria though. The lines are personal and mostly arbitrary.

Meh, if you try and split hairs, even assembly has magic in it nowdays. Not all instructions take the same amount of time. Some flush caches, thus cause unexpected memory behavior, etc. However, I think it is fair that most people learn roughly what the side effects are of each line at a local level. Ironically, this is an argument against many functional languages. There are not side effects of the logic, per se. Ho…

Like I said - it's mostly arbitrary. ;)

That said I think the issues with assembly you mention aren't magic as such, they're just consequences of the commands. They don't really hide much (if anything) behind the scenes that you'd have access to anyhow.

It's just that CPUs do so much more than they used to.

Re: How JavaScript works: memory management and common memory leaks

#18
post #10

Jump straight to "The four types of common JavaScript leaks" section: https://blog.sessionstack.com/how-javascript-works-memory-ma...

Didn't jump for me, but this should: https://blog.sessionstack.com/how-javascript-works-memory-ma...

Re: How JavaScript works: memory management and common memory leaks

#20
post #18
post #10

Jump straight to "The four types of common JavaScript leaks" section: https://blog.sessionstack.com/how-javascript-works-memory-ma...

Didn't jump for me, but this should: https://blog.sessionstack.com/how-javascript-works-memory-ma...

Oops, it looks like medium removes the hash on load so my copy/paste didn't work. I fixed my link.
Post reply on HN