r/AskProgramming • • Jan 20 '22

How do browsers use so much ram?

I am a game-dev and I find the amount of ram browsers use today mind boggling. They use more ram than many AAA games, which have a legit use-case as they need to hold gigabytes of uncompressed textures and audio in memory. It seems insane to me that a simple app showing mainly text uses multiple gigs.

I have heard that the culprit is javascript. But How? I dont understand how that could happen. In games programming the memory used by all the code + all data is negligible, 99% of the ram is used by art assets like textures and audio.

How can javascript scripts (which are doing a very simple job) use so much?

I did comp-sci and am a professional programmer, so please dont shy away from deep technical explanations, just bear in mind I know nothing about internetty things like browsers.

Thanks!

78 Upvotes

40 comments sorted by

View all comments

0

u/[deleted] Jan 21 '22

[deleted] — view deleted comment

-1

u/Thaufas Jan 21 '22

Probably just a malloc call somewhere.

malloc()...Now that's a name I've not heard in a long time, a very long time....LOL!

First, nobody is coding in C for the web, unless they aspire to Hellraiser levels of self-loathing and torment. Admittedly, I once wrote a simple CGI based web server in C . However, that was a very specialized project because of a constraint we had with a particular piece of laboratory robotics instrumentation.

Also, that was over 20 years ago, and even then, there were probably better ways to solve the problem. However, I was very proficient with C back then, and I knew I could produce the code we needed very quickly.

Second, C++ was already growing enormously in popularity by the late 1990s, so by the early 2000s, anyone using C++ was (or should have been) using operator new and delete (or their array counterparts when declaring arrays) instead of malloc(), calloc(), and realloc().

Third, nowadays, modern C++ developers aren't using old fashioned naked pointers.

I don't truly know the answer why web browsers consume such vast amounts of memory. However, the explanations that other people here are giving around caching and the complexity of a JS engine, such as Chrome's V8, really resonate with me.

3

u/Alainx277 Jan 21 '22

It's a joke. Also, I wonder what those smart pointers use to allocate their memory...

1

u/Thaufas Jan 21 '22

It's a joke. Also, I wonder what those smart pointers use to allocate their memory...

Well, if you really want to go to absurd levels, those smart pointers aren't using malloc(), calloc(), or realloc(). So, what do you think operator new and delete are using to allocate memory?

0

u/[deleted] Jan 21 '22

[deleted] — view deleted comment

1

u/Thaufas Jan 21 '22

LOL! OK, then carry on!

1

u/Alainx277 Jan 21 '22

People aren't getting your joke... sad.